github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/api/storage/client_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  	"github.com/juju/names"
     8  	jc "github.com/juju/testing/checkers"
     9  	gc "gopkg.in/check.v1"
    10  
    11  	basetesting "github.com/juju/juju/api/base/testing"
    12  	"github.com/juju/juju/api/storage"
    13  	"github.com/juju/juju/apiserver/params"
    14  	"github.com/juju/juju/testing"
    15  	"github.com/juju/utils/set"
    16  )
    17  
    18  type storageMockSuite struct {
    19  	testing.BaseSuite
    20  }
    21  
    22  var _ = gc.Suite(&storageMockSuite{})
    23  
    24  func (s *storageMockSuite) TestShow(c *gc.C) {
    25  	var called bool
    26  
    27  	one := "shared-fs/0"
    28  	oneTag := names.NewStorageTag(one)
    29  	two := "db-dir/1000"
    30  	twoTag := names.NewStorageTag(two)
    31  	expected := set.NewStrings(oneTag.String(), twoTag.String())
    32  
    33  	apiCaller := basetesting.APICallerFunc(
    34  		func(objType string,
    35  			version int,
    36  			id, request string,
    37  			a, result interface{},
    38  		) error {
    39  			called = true
    40  			c.Check(objType, gc.Equals, "Storage")
    41  			c.Check(id, gc.Equals, "")
    42  			c.Check(request, gc.Equals, "Show")
    43  
    44  			args, ok := a.(params.Entities)
    45  			c.Assert(ok, jc.IsTrue)
    46  			c.Assert(args.Entities, gc.HasLen, 2)
    47  
    48  			if results, k := result.(*params.StorageShowResults); k {
    49  				instances := make([]params.StorageShowResult, len(args.Entities))
    50  				for i, entity := range args.Entities {
    51  					c.Assert(expected.Contains(entity.Tag), jc.IsTrue)
    52  					instances[i] = params.StorageShowResult{
    53  						Result: params.StorageInstance{StorageTag: entity.Tag},
    54  					}
    55  				}
    56  				results.Results = instances
    57  			}
    58  
    59  			return nil
    60  		})
    61  	storageClient := storage.NewClient(apiCaller)
    62  	tags := []names.StorageTag{oneTag, twoTag}
    63  	found, err := storageClient.Show(tags)
    64  	c.Assert(err, jc.ErrorIsNil)
    65  	c.Assert(found, gc.HasLen, 2)
    66  	c.Assert(expected.Contains(found[0].StorageTag), jc.IsTrue)
    67  	c.Assert(expected.Contains(found[1].StorageTag), jc.IsTrue)
    68  	c.Assert(called, jc.IsTrue)
    69  }