-
Notifications
You must be signed in to change notification settings - Fork 894
feat: Output username and password for code server --dev
#1193
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package cli_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"crypto/ecdsa" | ||
"crypto/elliptic" | ||
|
@@ -18,6 +19,7 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/goleak" | ||
|
||
|
@@ -73,9 +75,17 @@ func TestServer(t *testing.T) { | |
ctx, cancelFunc := context.WithCancel(context.Background()) | ||
defer cancelFunc() | ||
root, cfg := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0") | ||
var stdoutBuf bytes.Buffer | ||
root.SetOutput(&stdoutBuf) | ||
go func() { | ||
err := root.ExecuteContext(ctx) | ||
require.ErrorIs(t, err, context.Canceled) | ||
|
||
// Verify that credentials were output to the terminal. | ||
wantEmail := "email: admin@coder.com" | ||
wantPassword := "password: password" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could export There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's definitely an option, we discussed it a bit and I added a commit that this this but ultimately dropped it before the merge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, I should've read back before I commented! |
||
assert.Contains(t, stdoutBuf.String(), wantEmail, "expected output %q; got no match", wantEmail) | ||
assert.Contains(t, stdoutBuf.String(), wantPassword, "expected output %q; got no match", wantPassword) | ||
}() | ||
var token string | ||
require.Eventually(t, func() bool { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit: if you're only ever calling
buffer.String()
you can usestrings.Builder
to avoid a copy on each call toString()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I didn't consider
strings.Builder
in this scenario although I did note the multiple calls toString()
but thought it would be acceptable for a test. Would you like me to do a follow-up PR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope! Not important at all, just thought I'd mention.