Skip to content

Commit

Permalink
fix(setup): Fix prompt, add a test for --anonymous
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop committed Aug 7, 2020
1 parent 01f407f commit 3b2c58a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (o *SetupOptions) DoSetup(f Factory) (err error) {
if o.Username != "" {
cfg.Profile.Peername = o.Username
} else if !o.Anonymous {
cfg.Profile.Peername = inputText(o.Out, o.In, "choose username (leave empty to generate a default name):", "")
cfg.Profile.Peername = prompt(o.Out, o.In, "choose username (leave empty to generate a default name):")
}

// If a username was passed with the --username flag or entered by prompt, make sure its valid
Expand Down
34 changes: 34 additions & 0 deletions cmd/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,40 @@ func TestSetupUsernameOnStdin(t *testing.T) {
}
}

// Test that setup doesn't prompt if given anonymous flag
func TestSetupAnonymousIgnoresStdin(t *testing.T) {
ctx := context.Background()
info := test_peers.GetTestPeerInfo(0)

qriHome := createTmpQriHome(t)
stdinText := "qri_test_name"
cmd, shutdown := newCommandWithStdin(ctx, qriHome, stdinText, repotest.NewTestCrypto())

cmdText := "qri setup --anonymous"
if err := executeCommand(cmd, cmdText); err != nil {
timedShutdown(fmt.Sprintf("ExecCommand: %q\n", cmdText), shutdown)
t.Fatal(err)
}

configData := readConfigFile(t, qriHome)

username := configData["Profile"].(map[string]interface{})["peername"]
expect := "testnick"
if username != expect {
t.Errorf("setup didn't create correct username, expect: %s, got: %s", expect, username)
}

profileID := configData["Profile"].(map[string]interface{})["id"]
if profileID != info.EncodedPeerID {
t.Errorf("setup didn't create correct profileID, expect: %s, got: %s", info.EncodedPeerID, profileID)
}

privkey := configData["Profile"].(map[string]interface{})["privkey"]
if privkey != info.EncodedPrivKey {
t.Errorf("setup didn't create correct private key")
}
}

// Test that setup with the --username flag will use that value
func TestSetupUsernameFlag(t *testing.T) {
ctx := context.Background()
Expand Down

0 comments on commit 3b2c58a

Please sign in to comment.