github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/worker/uniter/resolver/mock_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package resolver_test 5 6 import ( 7 "github.com/juju/testing" 8 9 "github.com/juju/juju/worker/fortress" 10 "github.com/juju/juju/worker/uniter/hook" 11 "github.com/juju/juju/worker/uniter/operation" 12 "github.com/juju/juju/worker/uniter/remotestate" 13 ) 14 15 type mockRemoteStateWatcher struct { 16 remotestate.RemoteStateWatcher 17 changes chan struct{} 18 snapshot remotestate.Snapshot 19 } 20 21 func (w *mockRemoteStateWatcher) RemoteStateChanged() <-chan struct{} { 22 return w.changes 23 } 24 25 func (w *mockRemoteStateWatcher) Snapshot() remotestate.Snapshot { 26 return w.snapshot 27 } 28 29 type mockOpFactory struct { 30 operation.Factory 31 testing.Stub 32 op mockOp 33 } 34 35 func (f *mockOpFactory) NewInstall(charmURL string) (operation.Operation, error) { 36 f.MethodCall(f, "NewInstall", charmURL) 37 return f.op, f.NextErr() 38 } 39 40 func (f *mockOpFactory) NewUpgrade(charmURL string) (operation.Operation, error) { 41 f.MethodCall(f, "NewUpgrade", charmURL) 42 return f.op, f.NextErr() 43 } 44 45 func (f *mockOpFactory) NewRevertUpgrade(charmURL string) (operation.Operation, error) { 46 f.MethodCall(f, "NewRevertUpgrade", charmURL) 47 return f.op, f.NextErr() 48 } 49 50 func (f *mockOpFactory) NewResolvedUpgrade(charmURL string) (operation.Operation, error) { 51 f.MethodCall(f, "NewResolvedUpgrade", charmURL) 52 return f.op, f.NextErr() 53 } 54 55 func (f *mockOpFactory) NewRunHook(info hook.Info) (operation.Operation, error) { 56 f.MethodCall(f, "NewRunHook", info) 57 return f.op, f.NextErr() 58 } 59 60 func (f *mockOpFactory) NewSkipHook(info hook.Info) (operation.Operation, error) { 61 f.MethodCall(f, "NewSkipHook", info) 62 return f.op, f.NextErr() 63 } 64 65 func (f *mockOpFactory) NewAction(id string) (operation.Operation, error) { 66 f.MethodCall(f, "NewAction", id) 67 return f.op, f.NextErr() 68 } 69 70 func (f *mockOpFactory) NewFailAction(id string) (operation.Operation, error) { 71 f.MethodCall(f, "NewFailAction", id) 72 return f.op, f.NextErr() 73 } 74 75 func (f *mockOpFactory) NewRemoteInit(runningStatus remotestate.ContainerRunningStatus) (operation.Operation, error) { 76 f.MethodCall(f, "NewRemoteInit", runningStatus) 77 return f.op, f.NextErr() 78 } 79 80 func (f *mockOpFactory) NewSkipRemoteInit(retry bool) (operation.Operation, error) { 81 f.MethodCall(f, "NewSkipRemoteInit", retry) 82 return f.op, f.NextErr() 83 } 84 85 type mockOpExecutor struct { 86 operation.Executor 87 testing.Stub 88 st operation.State 89 run func(operation.Operation, <-chan remotestate.Snapshot) error 90 } 91 92 func (e *mockOpExecutor) State() operation.State { 93 e.MethodCall(e, "State") 94 return e.st 95 } 96 97 func (e *mockOpExecutor) Run(op operation.Operation, rs <-chan remotestate.Snapshot) error { 98 e.MethodCall(e, "Run", op, rs) 99 if e.run != nil { 100 return e.run(op, rs) 101 } 102 return e.NextErr() 103 } 104 105 type mockOp struct { 106 operation.Operation 107 commit func(operation.State) (*operation.State, error) 108 prepare func(operation.State) (*operation.State, error) 109 } 110 111 func (op mockOp) Prepare(st operation.State) (*operation.State, error) { 112 if op.prepare != nil { 113 return op.prepare(st) 114 } 115 return &st, nil 116 } 117 118 func (op mockOp) Commit(st operation.State) (*operation.State, error) { 119 if op.commit != nil { 120 return op.commit(st) 121 } 122 return &st, nil 123 } 124 125 type mockCharmDirGuard struct { 126 fortress.Guard 127 testing.Stub 128 } 129 130 func (l *mockCharmDirGuard) Unlock() error { 131 l.MethodCall(l, "Unlock") 132 return l.NextErr() 133 } 134 135 func (l *mockCharmDirGuard) Lockdown(abort fortress.Abort) error { 136 l.MethodCall(l, "Lockdown", abort) 137 return l.NextErr() 138 }