github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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  	"gopkg.in/juju/charm.v6"
     9  
    10  	"github.com/juju/juju/worker/fortress"
    11  	"github.com/juju/juju/worker/uniter/hook"
    12  	"github.com/juju/juju/worker/uniter/operation"
    13  	"github.com/juju/juju/worker/uniter/remotestate"
    14  )
    15  
    16  type mockRemoteStateWatcher struct {
    17  	remotestate.RemoteStateWatcher
    18  	changes  chan struct{}
    19  	snapshot remotestate.Snapshot
    20  }
    21  
    22  func (w *mockRemoteStateWatcher) RemoteStateChanged() <-chan struct{} {
    23  	return w.changes
    24  }
    25  
    26  func (w *mockRemoteStateWatcher) Snapshot() remotestate.Snapshot {
    27  	return w.snapshot
    28  }
    29  
    30  type mockOpFactory struct {
    31  	operation.Factory
    32  	testing.Stub
    33  	op mockOp
    34  }
    35  
    36  func (f *mockOpFactory) NewUpgrade(charmURL *charm.URL) (operation.Operation, error) {
    37  	f.MethodCall(f, "NewUpgrade", charmURL)
    38  	return f.op, f.NextErr()
    39  }
    40  
    41  func (f *mockOpFactory) NewNoOpUpgrade(charmURL *charm.URL) (operation.Operation, error) {
    42  	f.MethodCall(f, "NewNoOpUpgrade", charmURL)
    43  	return f.op, f.NextErr()
    44  }
    45  
    46  func (f *mockOpFactory) NewRevertUpgrade(charmURL *charm.URL) (operation.Operation, error) {
    47  	f.MethodCall(f, "NewRevertUpgrade", charmURL)
    48  	return f.op, f.NextErr()
    49  }
    50  
    51  func (f *mockOpFactory) NewResolvedUpgrade(charmURL *charm.URL) (operation.Operation, error) {
    52  	f.MethodCall(f, "NewResolvedUpgrade", charmURL)
    53  	return f.op, f.NextErr()
    54  }
    55  
    56  func (f *mockOpFactory) NewRunHook(info hook.Info) (operation.Operation, error) {
    57  	f.MethodCall(f, "NewRunHook", info)
    58  	return f.op, f.NextErr()
    59  }
    60  
    61  func (f *mockOpFactory) NewSkipHook(info hook.Info) (operation.Operation, error) {
    62  	f.MethodCall(f, "NewSkipHook", info)
    63  	return f.op, f.NextErr()
    64  }
    65  
    66  func (f *mockOpFactory) NewAction(id string) (operation.Operation, error) {
    67  	f.MethodCall(f, "NewAction", id)
    68  	return f.op, f.NextErr()
    69  }
    70  
    71  type mockOpExecutor struct {
    72  	operation.Executor
    73  	testing.Stub
    74  	st operation.State
    75  }
    76  
    77  func (e *mockOpExecutor) State() operation.State {
    78  	e.MethodCall(e, "State")
    79  	return e.st
    80  }
    81  
    82  func (e *mockOpExecutor) Run(op operation.Operation) error {
    83  	e.MethodCall(e, "Run", op)
    84  	return e.NextErr()
    85  }
    86  
    87  type mockOp struct {
    88  	operation.Operation
    89  	commit  func(operation.State) (*operation.State, error)
    90  	prepare func(operation.State) (*operation.State, error)
    91  }
    92  
    93  func (op mockOp) Prepare(st operation.State) (*operation.State, error) {
    94  	if op.prepare != nil {
    95  		return op.prepare(st)
    96  	}
    97  	return &st, nil
    98  }
    99  
   100  func (op mockOp) Commit(st operation.State) (*operation.State, error) {
   101  	if op.commit != nil {
   102  		return op.commit(st)
   103  	}
   104  	return &st, nil
   105  }
   106  
   107  type mockCharmDirGuard struct {
   108  	fortress.Guard
   109  	testing.Stub
   110  	commit func(operation.State) (*operation.State, error)
   111  }
   112  
   113  func (l *mockCharmDirGuard) Unlock() error {
   114  	l.MethodCall(l, "Unlock")
   115  	return l.NextErr()
   116  }
   117  
   118  func (l *mockCharmDirGuard) Lockdown(abort fortress.Abort) error {
   119  	l.MethodCall(l, "Lockdown", abort)
   120  	return l.NextErr()
   121  }