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

Function TestAddInteractiveSkipsSaveWhenNothingChanged

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

Source from the content-addressed store, hash-verified

102}
103
104func TestAddInteractiveSkipsSaveWhenNothingChanged(t *testing.T) {
105 is := is.New(t)
106
107 cfg := &storageMock{
108 LookupFunc: func(name string) ([]config.Entry, bool) {
109 return []config.Entry{
110 {Key: userNameKey, Value: "Jane Doe"},
111 {Key: userEmailKey, Value: "work@example.com"},
112 }, true
113 },
114 SaveFunc: func(filename string) error {
115 return errors.New("save should not be called")
116 },
117 StoreFunc: func(profile string, key string, value string) {
118 t.Fatalf("Store should not be called")
119 },
120 }
121
122 var b bytes.Buffer
123
124 cmd := addCommand(
125 cfg,
126 func(_ io.Reader, _ io.Writer) (string, error) {
127 return "work", nil
128 },
129 func(initial ui.ProfileFormData, _ io.Reader, _ io.Writer) (ui.ProfileFormData, error) {
130 is.Equal(initial.Profile, "work")
131
132 return ui.ProfileFormData{
133 Profile: "work",
134 UserName: "Jane Doe",
135 UserEmail: "work@example.com",
136 UserSigningKey: "",
137 }, nil
138 },
139 )
140 cmd.SetOut(&b)
141 cmd.SetArgs(nil)
142
143 err := cmd.Execute()
144
145 is.NoErr(err)
146 is.Equal(len(cfg.StoreCalls()), 0)
147 is.Equal(len(cfg.SaveCalls()), 0)
148 is.Equal(trim(b.String()), "No profile changes to save.")
149}
150
151func TestAddInteractiveAbortDoesNotPrintSaveError(t *testing.T) {
152 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