github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/featuretests/storage_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package featuretests 5 6 import ( 7 "strings" 8 9 "github.com/juju/cmd" 10 jc "github.com/juju/testing/checkers" 11 gc "gopkg.in/check.v1" 12 13 "github.com/juju/juju/api" 14 "github.com/juju/juju/api/storage" 15 "github.com/juju/juju/cmd/envcmd" 16 cmdstorage "github.com/juju/juju/cmd/juju/storage" 17 "github.com/juju/juju/feature" 18 "github.com/juju/juju/juju" 19 jujutesting "github.com/juju/juju/juju/testing" 20 "github.com/juju/juju/testing" 21 "github.com/juju/names" 22 ) 23 24 type apiStorageSuite struct { 25 jujutesting.JujuConnSuite 26 storageClient *storage.Client 27 } 28 29 var _ = gc.Suite(&apiStorageSuite{}) 30 31 func (s *apiStorageSuite) SetUpTest(c *gc.C) { 32 s.JujuConnSuite.SetUpTest(c) 33 s.SetFeatureFlags(feature.Storage) 34 conn, err := juju.NewAPIState(s.AdminUserTag(c), s.Environ, api.DialOpts{}) 35 c.Assert(err, jc.ErrorIsNil) 36 s.AddCleanup(func(*gc.C) { conn.Close() }) 37 38 s.storageClient = storage.NewClient(conn) 39 c.Assert(s.storageClient, gc.NotNil) 40 } 41 42 func (s *apiStorageSuite) TearDownTest(c *gc.C) { 43 s.storageClient.ClientFacade.Close() 44 s.JujuConnSuite.TearDownTest(c) 45 } 46 47 func (s *apiStorageSuite) TestStorageShow(c *gc.C) { 48 // TODO(anastasiamac) update when s.Factory.MakeStorage or similar is available 49 storageTag := names.NewStorageTag("shared-fs/0") 50 found, err := s.storageClient.Show([]names.StorageTag{storageTag}) 51 c.Assert(err.Error(), gc.Matches, ".*permission denied.*") 52 c.Assert(found, gc.HasLen, 0) 53 } 54 55 type cmdStorageSuite struct { 56 jujutesting.RepoSuite 57 } 58 59 var _ = gc.Suite(&cmdStorageSuite{}) 60 61 func (s *cmdStorageSuite) SetUpTest(c *gc.C) { 62 s.RepoSuite.SetUpTest(c) 63 s.SetFeatureFlags(feature.Storage) 64 } 65 66 func runShow(c *gc.C, args []string) *cmd.Context { 67 context, err := testing.RunCommand(c, envcmd.Wrap(&cmdstorage.ShowCommand{}), args...) 68 c.Assert(err.Error(), gc.Matches, ".*permission denied.*") 69 return context 70 } 71 72 func (s *cmdStorageSuite) TestStorageShowCmdStack(c *gc.C) { 73 // TODO(anastasiamac) update when s.Factory.MakeStorage or similar is available 74 context := runShow(c, []string{"shared-fs/0"}) 75 obtained := strings.Replace(testing.Stdout(context), "\n", "", -1) 76 expected := "" 77 c.Assert(obtained, gc.Equals, expected) 78 }