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

Commit8661f92

Browse files
authored
feat: Output username and password forcode server --dev (#1193)
Fixes#825
1 parent0b1ee33 commit8661f92

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

‎cli/server.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ import (
4747
"github.com/coder/coder/provisionersdk/proto"
4848
)
4949

50+
vardefaultDevUser= codersdk.CreateFirstUserRequest{
51+
Email:"admin@coder.com",
52+
Username:"developer",
53+
Password:"password",
54+
OrganizationName:"acme-corp",
55+
}
56+
5057
// nolint:gocyclo
5158
funcserver()*cobra.Command {
5259
var (
@@ -275,6 +282,9 @@ func server() *cobra.Command {
275282
iferr!=nil {
276283
returnxerrors.Errorf("create first user: %w",err)
277284
}
285+
_,_=fmt.Fprintf(cmd.ErrOrStderr(),"email: %s\n",defaultDevUser.Email)
286+
_,_=fmt.Fprintf(cmd.ErrOrStderr(),"password: %s\n",defaultDevUser.Password)
287+
_,_=fmt.Fprintln(cmd.ErrOrStderr())
278288

279289
_,_=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 `+
280290
cliui.Styles.Field.Render("ctrl+c")+` to clean up provisioned infrastructure.`)+"\n\n")
@@ -441,18 +451,13 @@ func server() *cobra.Command {
441451
}
442452

443453
funccreateFirstUser(cmd*cobra.Command,client*codersdk.Client,cfg config.Root)error {
444-
_,err:=client.CreateFirstUser(cmd.Context(), codersdk.CreateFirstUserRequest{
445-
Email:"admin@coder.com",
446-
Username:"developer",
447-
Password:"password",
448-
OrganizationName:"acme-corp",
449-
})
454+
_,err:=client.CreateFirstUser(cmd.Context(),defaultDevUser)
450455
iferr!=nil {
451456
returnxerrors.Errorf("create first user: %w",err)
452457
}
453458
token,err:=client.LoginWithPassword(cmd.Context(), codersdk.LoginWithPasswordRequest{
454-
Email:"admin@coder.com",
455-
Password:"password",
459+
Email:defaultDevUser.Email,
460+
Password:defaultDevUser.Password,
456461
})
457462
iferr!=nil {
458463
returnxerrors.Errorf("login with first user: %w",err)

‎cli/server_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli_test
22

33
import (
4+
"bytes"
45
"context"
56
"crypto/ecdsa"
67
"crypto/elliptic"
@@ -18,6 +19,7 @@ import (
1819
"testing"
1920
"time"
2021

22+
"github.com/stretchr/testify/assert"
2123
"github.com/stretchr/testify/require"
2224
"go.uber.org/goleak"
2325

@@ -73,9 +75,17 @@ func TestServer(t *testing.T) {
7375
ctx,cancelFunc:=context.WithCancel(context.Background())
7476
defercancelFunc()
7577
root,cfg:=clitest.New(t,"server","--dev","--skip-tunnel","--address",":0")
78+
varstdoutBuf bytes.Buffer
79+
root.SetOutput(&stdoutBuf)
7680
gofunc() {
7781
err:=root.ExecuteContext(ctx)
7882
require.ErrorIs(t,err,context.Canceled)
83+
84+
// Verify that credentials were output to the terminal.
85+
wantEmail:="email: admin@coder.com"
86+
wantPassword:="password: password"
87+
assert.Contains(t,stdoutBuf.String(),wantEmail,"expected output %q; got no match",wantEmail)
88+
assert.Contains(t,stdoutBuf.String(),wantPassword,"expected output %q; got no match",wantPassword)
7989
}()
8090
vartokenstring
8191
require.Eventually(t,func()bool {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp