2022-04-25 01:08:26 +00:00
|
|
|
package cli_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-05-24 07:58:39 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-04-25 01:08:26 +00:00
|
|
|
|
2023-08-18 18:55:43 +00:00
|
|
|
"github.com/coder/coder/v2/cli/clitest"
|
|
|
|
"github.com/coder/coder/v2/coderd/coderdtest"
|
|
|
|
"github.com/coder/coder/v2/pty/ptytest"
|
2022-04-25 01:08:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUserCreate(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Run("Prompts", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
client := coderdtest.New(t, nil)
|
|
|
|
coderdtest.CreateFirstUser(t, client)
|
2023-03-23 22:42:20 +00:00
|
|
|
inv, root := clitest.New(t, "users", "create")
|
2022-04-25 01:08:26 +00:00
|
|
|
clitest.SetupConfig(t, client, root)
|
|
|
|
doneChan := make(chan struct{})
|
2023-03-23 22:42:20 +00:00
|
|
|
pty := ptytest.New(t).Attach(inv)
|
2022-04-25 01:08:26 +00:00
|
|
|
go func() {
|
|
|
|
defer close(doneChan)
|
2023-03-23 22:42:20 +00:00
|
|
|
err := inv.Run()
|
2022-05-24 07:58:39 +00:00
|
|
|
assert.NoError(t, err)
|
2022-04-25 01:08:26 +00:00
|
|
|
}()
|
|
|
|
matches := []string{
|
|
|
|
"Username", "dean",
|
|
|
|
"Email", "dean@coder.com",
|
|
|
|
}
|
|
|
|
for i := 0; i < len(matches); i += 2 {
|
|
|
|
match := matches[i]
|
|
|
|
value := matches[i+1]
|
|
|
|
pty.ExpectMatch(match)
|
|
|
|
pty.WriteLine(value)
|
|
|
|
}
|
|
|
|
<-doneChan
|
|
|
|
})
|
|
|
|
}
|