github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/apiserver/uniter/uniter_v2_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package uniter_test
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	"github.com/juju/utils"
     9  	gc "gopkg.in/check.v1"
    10  
    11  	"github.com/juju/juju/apiserver/uniter"
    12  	"github.com/juju/juju/state"
    13  	"github.com/juju/juju/storage"
    14  	jujufactory "github.com/juju/juju/testing/factory"
    15  )
    16  
    17  //TODO run all common V0 and V1 tests.
    18  type uniterV2Suite struct {
    19  	uniterBaseSuite
    20  	uniter *uniter.UniterAPIV2
    21  }
    22  
    23  var _ = gc.Suite(&uniterV2Suite{})
    24  
    25  func (s *uniterV2Suite) SetUpTest(c *gc.C) {
    26  	s.uniterBaseSuite.setUpTest(c)
    27  
    28  	uniterAPIV2, err := uniter.NewUniterAPIV2(
    29  		s.State,
    30  		s.resources,
    31  		s.authorizer,
    32  	)
    33  	c.Assert(err, jc.ErrorIsNil)
    34  	s.uniter = uniterAPIV2
    35  }
    36  
    37  func (s *uniterV2Suite) TestStorageInstances(c *gc.C) {
    38  	// We need to set up a unit that has storage metadata defined.
    39  	ch := s.AddTestingCharm(c, "storage-block")
    40  	sCons := map[string]state.StorageConstraints{
    41  		"data": {Pool: "", Size: 1024, Count: 1},
    42  	}
    43  	service := s.AddTestingServiceWithStorage(c, "storage-block", ch, sCons)
    44  	factory := jujufactory.NewFactory(s.State)
    45  	unit := factory.MakeUnit(c, &jujufactory.UnitParams{
    46  		Service: service,
    47  	})
    48  
    49  	password, err := utils.RandomPassword()
    50  	err = unit.SetPassword(password)
    51  	c.Assert(err, jc.ErrorIsNil)
    52  	st := s.OpenAPIAs(c, unit.Tag(), password)
    53  	uniter, err := st.Uniter()
    54  	c.Assert(err, jc.ErrorIsNil)
    55  	instances, err := uniter.StorageInstances(unit.Tag())
    56  	c.Assert(err, jc.ErrorIsNil)
    57  	c.Assert(instances, gc.DeepEquals, []storage.StorageInstance{
    58  		{Id: "data/0", Kind: storage.StorageKindBlock, Location: ""},
    59  	})
    60  }