mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
* chore: golangci: add linter rule to report usage of t.FailNow inside goroutines * chore: avoid t.FailNow in goroutines to appease the race detector
45 lines
963 B
Go
45 lines
963 B
Go
package cliui_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/cli/cliui"
|
|
"github.com/coder/coder/pty/ptytest"
|
|
)
|
|
|
|
func TestSelect(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("Select", func(t *testing.T) {
|
|
t.Parallel()
|
|
ptty := ptytest.New(t)
|
|
msgChan := make(chan string)
|
|
go func() {
|
|
resp, err := newSelect(ptty, cliui.SelectOptions{
|
|
Options: []string{"First", "Second"},
|
|
})
|
|
assert.NoError(t, err)
|
|
msgChan <- resp
|
|
}()
|
|
require.Equal(t, "First", <-msgChan)
|
|
})
|
|
}
|
|
|
|
func newSelect(ptty *ptytest.PTY, opts cliui.SelectOptions) (string, error) {
|
|
value := ""
|
|
cmd := &cobra.Command{
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
var err error
|
|
value, err = cliui.Select(cmd, opts)
|
|
return err
|
|
},
|
|
}
|
|
cmd.SetOutput(ptty.Output())
|
|
cmd.SetIn(ptty.Input())
|
|
return value, cmd.ExecuteContext(context.Background())
|
|
}
|