Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Output username and password forcode 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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 4 commits intomainfrommafredri/dev-mode-credentials
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletionscli/server.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,6 +47,13 @@ import (
"github.com/coder/coder/provisionersdk/proto"
)

var defaultDevUser = codersdk.CreateFirstUserRequest{
Email: "admin@coder.com",
Username: "developer",
Password: "password",
OrganizationName: "acme-corp",
}

// nolint:gocyclo
func server() *cobra.Command {
var (
Expand DownExpand Up@@ -275,6 +282,9 @@ func server() *cobra.Command {
if err != nil {
return xerrors.Errorf("create first user: %w", err)
}
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "email: %s\n", defaultDevUser.Email)
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "password: %s\n", defaultDevUser.Password)
_, _ = fmt.Fprintln(cmd.ErrOrStderr())

_, _ = fmt.Fprintf(cmd.ErrOrStderr(), cliui.Styles.Wrap.Render(`Started in dev mode. All data is in-memory! `+cliui.Styles.Bold.Render("Do not use in production")+`. Press `+
cliui.Styles.Field.Render("ctrl+c")+` to clean up provisioned infrastructure.`)+"\n\n")
Expand DownExpand Up@@ -441,18 +451,13 @@ func server() *cobra.Command {
}

func createFirstUser(cmd *cobra.Command, client *codersdk.Client, cfg config.Root) error {
_, err := client.CreateFirstUser(cmd.Context(), codersdk.CreateFirstUserRequest{
Email: "admin@coder.com",
Username: "developer",
Password: "password",
OrganizationName: "acme-corp",
})
_, err := client.CreateFirstUser(cmd.Context(), defaultDevUser)
if err != nil {
return xerrors.Errorf("create first user: %w", err)
}
token, err := client.LoginWithPassword(cmd.Context(), codersdk.LoginWithPasswordRequest{
Email:"admin@coder.com",
Password:"password",
Email:defaultDevUser.Email,
Password:defaultDevUser.Password,
})
if err != nil {
return xerrors.Errorf("login with first user: %w", err)
Expand Down
10 changes: 10 additions & 0 deletionscli/server_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
package cli_test

import (
"bytes"
"context"
"crypto/ecdsa"
"crypto/elliptic"
Expand All@@ -18,6 +19,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

Expand DownExpand Up@@ -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)
Comment on lines +78 to +79
Copy link
Contributor

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 callingbuffer.String() you can usestrings.Builder to avoid a copy on each call toString()

Copy link
MemberAuthor

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 considerstrings.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?

Copy link
Contributor

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.

mafredri reacted with thumbs up emoji
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe we could exportdefaultDevUser so we could assert the output in tests

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That's definitely an option, wediscussed it a bit and I added a commit that this this but ultimately dropped it before the merge.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp