(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func TestAddInteractiveStoresOnlyChangedFilledValues(t *testing.T) { |
| 54 | is := is.New(t) |
| 55 | |
| 56 | cfg := &storageMock{ |
| 57 | LookupFunc: func(name string) ([]config.Entry, bool) { |
| 58 | return []config.Entry{ |
| 59 | {Key: userNameKey, Value: "Jane Doe"}, |
| 60 | {Key: userEmailKey, Value: "old@example.com"}, |
| 61 | }, true |
| 62 | }, |
| 63 | SaveFunc: func(filename string) error { |
| 64 | return nil |
| 65 | }, |
| 66 | StoreFunc: func(profile string, key string, value string) {}, |
| 67 | } |
| 68 | |
| 69 | var b bytes.Buffer |
| 70 | |
| 71 | cmd := addCommand( |
| 72 | cfg, |
| 73 | func(_ io.Reader, _ io.Writer) (string, error) { |
| 74 | return "work", nil |
| 75 | }, |
| 76 | func(initial ui.ProfileFormData, _ io.Reader, _ io.Writer) (ui.ProfileFormData, error) { |
| 77 | is.Equal(initial.Profile, "work") |
| 78 | is.Equal(initial.UserName, "Jane Doe") |
| 79 | is.Equal(initial.UserEmail, "old@example.com") |
| 80 | is.Equal(initial.UserSigningKey, "") |
| 81 | |
| 82 | return ui.ProfileFormData{ |
| 83 | Profile: "work", |
| 84 | UserName: "Jane Doe", |
| 85 | UserEmail: "new@example.com", |
| 86 | UserSigningKey: "", |
| 87 | }, nil |
| 88 | }, |
| 89 | ) |
| 90 | cmd.SetOut(&b) |
| 91 | cmd.SetArgs(nil) |
| 92 | |
| 93 | err := cmd.Execute() |
| 94 | |
| 95 | is.NoErr(err) |
| 96 | is.Equal(len(cfg.StoreCalls()), 1) |
| 97 | is.Equal(cfg.StoreCalls()[0].Profile, "work") |
| 98 | is.Equal(cfg.StoreCalls()[0].Key, userEmailKey) |
| 99 | is.Equal(cfg.StoreCalls()[0].Value, "new@example.com") |
| 100 | is.Equal(len(cfg.SaveCalls()), 1) |
| 101 | is.Equal(trim(b.String()), "Successfully updated `work` profile.") |
| 102 | } |
| 103 | |
| 104 | func TestAddInteractiveSkipsSaveWhenNothingChanged(t *testing.T) { |
| 105 | is := is.New(t) |
nothing calls this directly
no test coverage detected