github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/facades/controller/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 a controller.
    18  type mockAuth struct {
    19  	facade.Authorizer
    20  	nonController bool
    21  }
    22  
    23  // AuthModelManager is part of the facade.Authorizer interface.
    24  func (mock mockAuth) AuthController() bool {
    25  	return !mock.nonController
    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  // ControllerTag is part of the singular.Backend interface.
    39  func (mock *mockBackend) ControllerTag() names.ControllerTag {
    40  	return coretesting.ControllerTag
    41  }
    42  
    43  // ModelTag is part of the singular.Backend interface.
    44  func (mock *mockBackend) ModelTag() names.ModelTag {
    45  	return coretesting.ModelTag
    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(leaseId string, cancel <-chan struct{}) error {
    56  	mock.stub.AddCall("WaitUntilExpired", leaseId)
    57  	select {
    58  	case <-cancel:
    59  		return lease.ErrWaitCancelled
    60  	default:
    61  	}
    62  	return mock.stub.NextErr()
    63  }