github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/uniter/storage/mock_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package storage_test
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"gopkg.in/juju/names.v2"
    10  
    11  	"github.com/juju/juju/apiserver/params"
    12  	"github.com/juju/juju/worker/uniter/hook"
    13  	"github.com/juju/juju/worker/uniter/operation"
    14  )
    15  
    16  type mockStorageAccessor struct {
    17  	storageAttachment             func(names.StorageTag, names.UnitTag) (params.StorageAttachment, error)
    18  	unitStorageAttachments        func(names.UnitTag) ([]params.StorageAttachmentId, error)
    19  	destroyUnitStorageAttachments func(names.UnitTag) error
    20  	remove                        func(names.StorageTag, names.UnitTag) error
    21  }
    22  
    23  func (m *mockStorageAccessor) StorageAttachment(s names.StorageTag, u names.UnitTag) (params.StorageAttachment, error) {
    24  	return m.storageAttachment(s, u)
    25  }
    26  
    27  func (m *mockStorageAccessor) UnitStorageAttachments(u names.UnitTag) ([]params.StorageAttachmentId, error) {
    28  	return m.unitStorageAttachments(u)
    29  }
    30  
    31  func (m *mockStorageAccessor) DestroyUnitStorageAttachments(u names.UnitTag) error {
    32  	return m.destroyUnitStorageAttachments(u)
    33  }
    34  
    35  func (m *mockStorageAccessor) RemoveStorageAttachment(s names.StorageTag, u names.UnitTag) error {
    36  	return m.remove(s, u)
    37  }
    38  
    39  type mockOperations struct {
    40  	operation.Factory
    41  }
    42  
    43  func (m *mockOperations) NewUpdateStorage(tags []names.StorageTag) (operation.Operation, error) {
    44  	return &mockOperation{"update storage"}, nil
    45  }
    46  
    47  func (m *mockOperations) NewRunHook(hookInfo hook.Info) (operation.Operation, error) {
    48  	return &mockOperation{fmt.Sprintf("run hook %v", hookInfo.Kind)}, nil
    49  }
    50  
    51  type mockOperation struct {
    52  	name string
    53  }
    54  
    55  func (m *mockOperation) String() string {
    56  	return m.name
    57  }
    58  
    59  func (m *mockOperation) NeedsGlobalMachineLock() bool {
    60  	return false
    61  }
    62  
    63  func (m *mockOperation) Prepare(state operation.State) (*operation.State, error) {
    64  	return &state, nil
    65  }
    66  
    67  func (m *mockOperation) Execute(state operation.State) (*operation.State, error) {
    68  	return &state, nil
    69  }
    70  
    71  func (m *mockOperation) Commit(state operation.State) (*operation.State, error) {
    72  	return &state, nil
    73  }