github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/apiserver/singular/fixture_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package singular_test 5 6 import ( 7 "time" 8 9 "github.com/juju/testing" 10 "gopkg.in/juju/names.v2" 11 12 "github.com/juju/juju/apiserver/facade" 13 "github.com/juju/juju/core/lease" 14 coretesting "github.com/juju/juju/testing" 15 ) 16 17 // mockAuth represents a machine which may or may not be an environ manager. 18 type mockAuth struct { 19 facade.Authorizer 20 nonManager bool 21 } 22 23 // AuthModelManager is part of the facade.Authorizer interface. 24 func (mock mockAuth) AuthModelManager() bool { 25 return !mock.nonManager 26 } 27 28 // GetAuthTag is part of the facade.Authorizer interface. 29 func (mockAuth) GetAuthTag() names.Tag { 30 return names.NewMachineTag("123") 31 } 32 33 // mockBackend implements singular.Backend and lease.Claimer. 34 type mockBackend struct { 35 stub testing.Stub 36 } 37 38 // ModelTag is part of the singular.Backend interface. 39 func (mock *mockBackend) ModelTag() names.ModelTag { 40 return coretesting.ModelTag 41 } 42 43 // SingularClaimer is part of the singular.Backend interface. 44 func (mock *mockBackend) SingularClaimer() lease.Claimer { 45 return mock 46 } 47 48 // Claim is part of the lease.Claimer interface. 49 func (mock *mockBackend) Claim(lease, holder string, duration time.Duration) error { 50 mock.stub.AddCall("Claim", lease, holder, duration) 51 return mock.stub.NextErr() 52 } 53 54 // WaitUntilExpired is part of the lease.Claimer interface. 55 func (mock *mockBackend) WaitUntilExpired(lease string) error { 56 mock.stub.AddCall("WaitUntilExpired", lease) 57 return mock.stub.NextErr() 58 }