@@ -29,8 +29,8 @@ type UpdatePkgMock struct {
2929 mock.Mock
3030}
3131
32- func (m * UpdatePkgMock ) CheckForUpdates (clients * shared.ClientFactory , cmd * cobra.Command ) error {
33- args := m .Called (clients , cmd )
32+ func (m * UpdatePkgMock ) CheckForUpdates (clients * shared.ClientFactory , cmd * cobra.Command , autoApprove bool ) error {
33+ args := m .Called (clients , cmd , autoApprove )
3434 return args .Error (0 )
3535}
3636
@@ -49,11 +49,26 @@ func TestUpgradeCommand(t *testing.T) {
4949 updatePkgMock := new (UpdatePkgMock )
5050 checkForUpdatesFunc = updatePkgMock .CheckForUpdates
5151
52- updatePkgMock .On ("CheckForUpdates" , mock .Anything , mock .Anything ).Return (nil )
52+ // Test default behavior (no auto-approve)
53+ updatePkgMock .On ("CheckForUpdates" , mock .Anything , mock .Anything , false ).Return (nil )
5354 err := cmd .ExecuteContext (ctx )
5455 if err != nil {
5556 assert .Fail (t , "cmd.Upgrade had unexpected error" )
5657 }
58+ updatePkgMock .AssertCalled (t , "CheckForUpdates" , mock .Anything , mock .Anything , false )
5759
58- updatePkgMock .AssertCalled (t , "CheckForUpdates" , mock .Anything , mock .Anything )
60+ // Test with auto-approve flag
61+ cmd = NewCommand (clients )
62+ testutil .MockCmdIO (clients .IO , cmd )
63+ cmd .SetArgs ([]string {"--auto-approve" })
64+
65+ updatePkgMock = new (UpdatePkgMock )
66+ checkForUpdatesFunc = updatePkgMock .CheckForUpdates
67+ updatePkgMock .On ("CheckForUpdates" , mock .Anything , mock .Anything , true ).Return (nil )
68+
69+ err = cmd .ExecuteContext (ctx )
70+ if err != nil {
71+ assert .Fail (t , "cmd.Upgrade with auto-approve had unexpected error" )
72+ }
73+ updatePkgMock .AssertCalled (t , "CheckForUpdates" , mock .Anything , mock .Anything , true )
5974}
0 commit comments