MCPcopy Create free account
hub / github.com/dotzero/git-profile / TestAddInteractiveStoresOnlyChangedFilledValues

Function TestAddInteractiveStoresOnlyChangedFilledValues

cmd/add_test.go:53–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func 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
104func TestAddInteractiveSkipsSaveWhenNothingChanged(t *testing.T) {
105 is := is.New(t)

Callers

nothing calls this directly

Calls 5

StoreCallsMethod · 0.95
SaveCallsMethod · 0.95
addCommandFunction · 0.85
trimFunction · 0.85
ExecuteMethod · 0.80

Tested by

no test coverage detected