github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/diskmanager/manifold_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package diskmanager_test
     5  
     6  import (
     7  	apidiskmanager "github.com/juju/juju/api/diskmanager"
     8  	jc "github.com/juju/testing/checkers"
     9  	gc "gopkg.in/check.v1"
    10  	"gopkg.in/juju/names.v2"
    11  
    12  	"github.com/juju/juju/agent"
    13  	basetesting "github.com/juju/juju/api/base/testing"
    14  	"github.com/juju/juju/state/multiwatcher"
    15  	coretesting "github.com/juju/juju/testing"
    16  	"github.com/juju/juju/worker"
    17  	"github.com/juju/juju/worker/diskmanager"
    18  )
    19  
    20  type manifoldSuite struct {
    21  	coretesting.BaseSuite
    22  }
    23  
    24  var _ = gc.Suite(&manifoldSuite{})
    25  
    26  func (s *manifoldSuite) TestMachineDiskmanager(c *gc.C) {
    27  
    28  	called := false
    29  
    30  	apiCaller := basetesting.APICallerFunc(
    31  		func(objType string,
    32  			version int,
    33  			id, request string,
    34  			a, response interface{},
    35  		) error {
    36  
    37  			// We don't test the api call. We test that NewWorker is
    38  			// passed the expected arguments.
    39  			return nil
    40  		})
    41  
    42  	s.PatchValue(&diskmanager.NewWorker, func(l diskmanager.ListBlockDevicesFunc, b diskmanager.BlockDeviceSetter) worker.Worker {
    43  		called = true
    44  
    45  		c.Assert(l, gc.FitsTypeOf, diskmanager.DefaultListBlockDevices)
    46  		c.Assert(b, gc.NotNil)
    47  
    48  		api, ok := b.(*apidiskmanager.State)
    49  		c.Assert(ok, jc.IsTrue)
    50  		c.Assert(api, gc.NotNil)
    51  
    52  		return nil
    53  	})
    54  
    55  	a := &dummyAgent{
    56  		tag: names.NewMachineTag("1"),
    57  		jobs: []multiwatcher.MachineJob{
    58  			multiwatcher.JobManageModel,
    59  		},
    60  	}
    61  
    62  	_, err := diskmanager.NewWorkerFunc(a, apiCaller)
    63  	c.Assert(err, jc.ErrorIsNil)
    64  	c.Assert(called, jc.IsTrue)
    65  }
    66  
    67  type dummyAgent struct {
    68  	agent.Agent
    69  	tag  names.Tag
    70  	jobs []multiwatcher.MachineJob
    71  }
    72  
    73  func (a dummyAgent) CurrentConfig() agent.Config {
    74  	return dummyCfg{
    75  		tag:  a.tag,
    76  		jobs: a.jobs,
    77  	}
    78  }
    79  
    80  type dummyCfg struct {
    81  	agent.Config
    82  	tag  names.Tag
    83  	jobs []multiwatcher.MachineJob
    84  }
    85  
    86  func (c dummyCfg) Tag() names.Tag {
    87  	return c.tag
    88  }