github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/apiserver/storage/filesystemlist_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/errors" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 11 "github.com/juju/juju/apiserver/params" 12 "github.com/juju/juju/state" 13 ) 14 15 type filesystemSuite struct { 16 baseStorageSuite 17 } 18 19 var _ = gc.Suite(&filesystemSuite{}) 20 21 func (s *filesystemSuite) expectedFilesystemDetails() params.FilesystemDetails { 22 return params.FilesystemDetails{ 23 FilesystemTag: s.filesystemTag.String(), 24 Status: params.EntityStatus{ 25 Status: "attached", 26 }, 27 MachineAttachments: map[string]params.FilesystemAttachmentInfo{ 28 s.machineTag.String(): params.FilesystemAttachmentInfo{}, 29 }, 30 Storage: ¶ms.StorageDetails{ 31 StorageTag: "storage-data-0", 32 OwnerTag: "unit-mysql-0", 33 Kind: params.StorageKindFilesystem, 34 Status: params.EntityStatus{ 35 Status: "attached", 36 }, 37 Attachments: map[string]params.StorageAttachmentDetails{ 38 "unit-mysql-0": params.StorageAttachmentDetails{ 39 StorageTag: "storage-data-0", 40 UnitTag: "unit-mysql-0", 41 MachineTag: "machine-66", 42 }, 43 }, 44 }, 45 } 46 } 47 48 func (s *filesystemSuite) TestListFilesystemsEmptyFilter(c *gc.C) { 49 found, err := s.api.ListFilesystems(params.FilesystemFilters{ 50 []params.FilesystemFilter{{}}, 51 }) 52 c.Assert(err, jc.ErrorIsNil) 53 c.Assert(found.Results, gc.HasLen, 1) 54 c.Assert(found.Results[0].Result, gc.HasLen, 1) 55 c.Assert(found.Results[0].Result[0], gc.DeepEquals, s.expectedFilesystemDetails()) 56 } 57 58 func (s *filesystemSuite) TestListFilesystemsError(c *gc.C) { 59 msg := "inventing error" 60 s.state.allFilesystems = func() ([]state.Filesystem, error) { 61 return nil, errors.New(msg) 62 } 63 results, err := s.api.ListFilesystems(params.FilesystemFilters{ 64 []params.FilesystemFilter{{}}, 65 }) 66 c.Assert(err, jc.ErrorIsNil) 67 c.Assert(results.Results, gc.HasLen, 1) 68 c.Assert(results.Results[0].Error, gc.ErrorMatches, msg) 69 } 70 71 func (s *filesystemSuite) TestListFilesystemsNoFilesystems(c *gc.C) { 72 s.state.allFilesystems = func() ([]state.Filesystem, error) { 73 return nil, nil 74 } 75 results, err := s.api.ListFilesystems(params.FilesystemFilters{}) 76 c.Assert(err, jc.ErrorIsNil) 77 c.Assert(results.Results, gc.HasLen, 0) 78 } 79 80 func (s *filesystemSuite) TestListFilesystemsFilter(c *gc.C) { 81 filters := []params.FilesystemFilter{{ 82 Machines: []string{s.machineTag.String()}, 83 }} 84 found, err := s.api.ListFilesystems(params.FilesystemFilters{filters}) 85 c.Assert(err, jc.ErrorIsNil) 86 c.Assert(found.Results, gc.HasLen, 1) 87 c.Assert(found.Results[0].Result, gc.HasLen, 1) 88 c.Assert(found.Results[0].Result[0], jc.DeepEquals, s.expectedFilesystemDetails()) 89 } 90 91 func (s *filesystemSuite) TestListFilesystemsFilterNonMatching(c *gc.C) { 92 filters := []params.FilesystemFilter{{ 93 Machines: []string{"machine-42"}, 94 }} 95 found, err := s.api.ListFilesystems(params.FilesystemFilters{filters}) 96 c.Assert(err, jc.ErrorIsNil) 97 c.Assert(found.Results, gc.HasLen, 1) 98 c.Assert(found.Results[0].Error, gc.IsNil) 99 c.Assert(found.Results[0].Result, gc.HasLen, 0) 100 } 101 102 func (s *filesystemSuite) TestListFilesystemsFilesystemInfo(c *gc.C) { 103 s.filesystem.info = &state.FilesystemInfo{ 104 Size: 123, 105 } 106 expected := s.expectedFilesystemDetails() 107 expected.Info.Size = 123 108 found, err := s.api.ListFilesystems(params.FilesystemFilters{ 109 []params.FilesystemFilter{{}}, 110 }) 111 c.Assert(err, jc.ErrorIsNil) 112 c.Assert(found.Results, gc.HasLen, 1) 113 c.Assert(found.Results[0].Result, gc.HasLen, 1) 114 c.Assert(found.Results[0].Result[0], jc.DeepEquals, expected) 115 } 116 117 func (s *filesystemSuite) TestListFilesystemsAttachmentInfo(c *gc.C) { 118 s.filesystemAttachment.info = &state.FilesystemAttachmentInfo{ 119 MountPoint: "/tmp", 120 ReadOnly: true, 121 } 122 expected := s.expectedFilesystemDetails() 123 expected.MachineAttachments[s.machineTag.String()] = params.FilesystemAttachmentInfo{ 124 MountPoint: "/tmp", 125 ReadOnly: true, 126 } 127 expectedStorageAttachmentDetails := expected.Storage.Attachments["unit-mysql-0"] 128 expectedStorageAttachmentDetails.Location = "/tmp" 129 expected.Storage.Attachments["unit-mysql-0"] = expectedStorageAttachmentDetails 130 found, err := s.api.ListFilesystems(params.FilesystemFilters{ 131 []params.FilesystemFilter{{}}, 132 }) 133 c.Assert(err, jc.ErrorIsNil) 134 c.Assert(found.Results, gc.HasLen, 1) 135 c.Assert(found.Results[0].Result, gc.HasLen, 1) 136 c.Assert(found.Results[0].Result[0], jc.DeepEquals, expected) 137 } 138 139 func (s *filesystemSuite) TestListFilesystemsVolumeBacked(c *gc.C) { 140 s.filesystem.volume = &s.volumeTag 141 expected := s.expectedFilesystemDetails() 142 expected.VolumeTag = s.volumeTag.String() 143 found, err := s.api.ListFilesystems(params.FilesystemFilters{ 144 []params.FilesystemFilter{{}}, 145 }) 146 c.Assert(err, jc.ErrorIsNil) 147 c.Assert(found.Results, gc.HasLen, 1) 148 c.Assert(found.Results[0].Result, gc.HasLen, 1) 149 c.Assert(found.Results[0].Result[0], jc.DeepEquals, expected) 150 }