-
Notifications
You must be signed in to change notification settings - Fork 894
feat: Add "coder" CLI #221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d6a1eb8
feat: Add "coder" CLI
kylecarbs 24cc781
Add CLI test for login
kylecarbs ddb5756
Add "bin/coder" target to Makefile
kylecarbs d8b4e88
Update promptui to fix race
kylecarbs fc6d9da
Fix error scope
kylecarbs 4f74b01
Don't run CLI tests on Windows
kylecarbs aed4a62
Fix requested changes
kylecarbs 6aec3a1
Merge branch 'main' into cli
kylecarbs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add CLI test for login
- Loading branch information
commit 24cc781cd023e9b851f7db98e8d78e57cce88788
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package clitest | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/coder/coder/cli" | ||
"github.com/coder/coder/cli/config" | ||
) | ||
|
||
func New(t *testing.T, args ...string) (*cobra.Command, config.Root) { | ||
cmd := cli.Root() | ||
dir := t.TempDir() | ||
root := config.Root(dir) | ||
cmd.SetArgs(append([]string{"--global-config", dir}, args...)) | ||
return cmd, root | ||
} | ||
|
||
func StdoutLogs(t *testing.T) io.Writer { | ||
reader, writer := io.Pipe() | ||
scanner := bufio.NewScanner(reader) | ||
t.Cleanup(func() { | ||
_ = reader.Close() | ||
_ = writer.Close() | ||
}) | ||
go func() { | ||
for scanner.Scan() { | ||
if scanner.Err() != nil { | ||
return | ||
} | ||
t.Log(scanner.Text()) | ||
} | ||
}() | ||
return writer | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cli_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/coder/coder/cli/clitest" | ||
"github.com/coder/coder/coderd/coderdtest" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/Netflix/go-expect" | ||
) | ||
|
||
func TestLogin(t *testing.T) { | ||
t.Parallel() | ||
t.Run("InitialUserNoTTY", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t) | ||
root, _ := clitest.New(t, "login", client.URL.String()) | ||
err := root.Execute() | ||
require.Error(t, err) | ||
}) | ||
|
||
t.Run("InitialUserTTY", func(t *testing.T) { | ||
t.Parallel() | ||
console, err := expect.NewConsole(expect.WithStdout(clitest.StdoutLogs(t))) | ||
require.NoError(t, err) | ||
client := coderdtest.New(t) | ||
root, _ := clitest.New(t, "login", client.URL.String()) | ||
root.SetIn(console.Tty()) | ||
root.SetOut(console.Tty()) | ||
go func() { | ||
err = root.Execute() | ||
require.NoError(t, err) | ||
}() | ||
|
||
matches := []string{ | ||
"first user?", "y", | ||
"username", "testuser", | ||
"organization", "testorg", | ||
"email", "user@coder.com", | ||
"password", "password", | ||
} | ||
for i := 0; i < len(matches); i += 2 { | ||
match := matches[i] | ||
value := matches[i+1] | ||
_, err = console.ExpectString(match) | ||
require.NoError(t, err) | ||
_, err = console.SendLine(value) | ||
require.NoError(t, err) | ||
} | ||
_, err = console.ExpectString("Welcome to Coder") | ||
require.NoError(t, err) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.