MCPcopy Create free account
hub / github.com/github/gh-aw / TestConfirmDefaultsUpdate

Function TestConfirmDefaultsUpdate

pkg/cli/env_command_test.go:249–286  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

247}
248
249func TestConfirmDefaultsUpdate(t *testing.T) {
250 target := defaultsTarget{scope: defaultsScopeOrg, org: "github"}
251 changes := []defaultsUpdateChange{{field: "default_max_turns", value: "42"}}
252
253 t.Run("requests confirmation by default", func(t *testing.T) {
254 called := false
255 confirmAction := func(title, affirmative, negative string) (bool, error) {
256 called = true
257 assert.Equal(t, "Do you want to update these defaults?", title)
258 assert.Equal(t, "Yes, update", affirmative)
259 assert.Equal(t, "No, cancel", negative)
260 return true, nil
261 }
262
263 err := confirmDefaultsUpdate(target, "defaults.yml", changes, false, confirmAction)
264 require.NoError(t, err)
265 assert.True(t, called)
266 })
267
268 t.Run("skips confirmation with yes", func(t *testing.T) {
269 confirmAction := func(title, affirmative, negative string) (bool, error) {
270 t.Fatal("confirmation should be skipped")
271 return false, nil
272 }
273
274 err := confirmDefaultsUpdate(target, "defaults.yml", changes, true, confirmAction)
275 require.NoError(t, err)
276 })
277
278 t.Run("returns cancellation error", func(t *testing.T) {
279 confirmAction := func(title, affirmative, negative string) (bool, error) {
280 return false, nil
281 }
282
283 err := confirmDefaultsUpdate(target, "defaults.yml", changes, false, confirmAction)
284 require.ErrorContains(t, err, "defaults update cancelled")
285 })
286}

Callers

nothing calls this directly

Calls 2

confirmDefaultsUpdateFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected