@@ -21,7 +21,7 @@ type storageSuite struct {
2121 coretesting.BaseSuite
2222}
2323
24- func (s * storageSuite ) TestStorageAttachments (c * gc.C ) {
24+ func (s * storageSuite ) TestUnitStorageAttachments (c * gc.C ) {
2525 storageAttachments := []params.StorageAttachment {{
2626 StorageTag : "storage-whatever-0" ,
2727 OwnerTag : "service-mysql" ,
@@ -35,7 +35,7 @@ func (s *storageSuite) TestStorageAttachments(c *gc.C) {
3535 c .Check (objType , gc .Equals , "Uniter" )
3636 c .Check (version , gc .Equals , 2 )
3737 c .Check (id , gc .Equals , "" )
38- c .Check (request , gc .Equals , "StorageAttachments " )
38+ c .Check (request , gc .Equals , "UnitStorageAttachments " )
3939 c .Check (arg , gc .DeepEquals , params.Entities {
4040 Entities : []params.Entity {{Tag : "unit-mysql-0" }},
4141 })
@@ -50,7 +50,7 @@ func (s *storageSuite) TestStorageAttachments(c *gc.C) {
5050 })
5151
5252 st := uniter .NewState (apiCaller , names .NewUnitTag ("mysql/0" ))
53- attachments , err := st .StorageAttachments (names .NewUnitTag ("mysql/0" ))
53+ attachments , err := st .UnitStorageAttachments (names .NewUnitTag ("mysql/0" ))
5454 c .Check (err , jc .ErrorIsNil )
5555 c .Check (called , jc .IsTrue )
5656 c .Assert (attachments , gc .DeepEquals , storageAttachments )
@@ -64,25 +64,27 @@ func (s *storageSuite) TestStorageAttachmentResultCountMismatch(c *gc.C) {
6464 return nil
6565 })
6666 st := uniter .NewState (apiCaller , names .NewUnitTag ("mysql/0" ))
67- c .Assert (func () { st .StorageAttachments (names .NewUnitTag ("mysql/0" )) }, gc .PanicMatches , "expected 1 result, got 2" )
67+ c .Assert (func () {
68+ st .UnitStorageAttachments (names .NewUnitTag ("mysql/0" ))
69+ }, gc .PanicMatches , "expected 1 result, got 2" )
6870}
6971
7072func (s * storageSuite ) TestAPIErrors (c * gc.C ) {
7173 apiCaller := testing .APICallerFunc (func (objType string , version int , id , request string , arg , result interface {}) error {
7274 return errors .New ("bad" )
7375 })
7476 st := uniter .NewState (apiCaller , names .NewUnitTag ("mysql/0" ))
75- _ , err := st .StorageAttachments (names .NewUnitTag ("mysql/0" ))
77+ _ , err := st .UnitStorageAttachments (names .NewUnitTag ("mysql/0" ))
7678 c .Check (err , gc .ErrorMatches , "bad" )
7779}
7880
79- func (s * storageSuite ) TestWatchStorageAttachments (c * gc.C ) {
81+ func (s * storageSuite ) TestWatchUnitStorageAttachments (c * gc.C ) {
8082 var called bool
8183 apiCaller := testing .APICallerFunc (func (objType string , version int , id , request string , arg , result interface {}) error {
8284 c .Check (objType , gc .Equals , "Uniter" )
8385 c .Check (version , gc .Equals , 2 )
8486 c .Check (id , gc .Equals , "" )
85- c .Check (request , gc .Equals , "WatchStorageAttachments " )
87+ c .Check (request , gc .Equals , "WatchUnitStorageAttachments " )
8688 c .Check (arg , gc .DeepEquals , params.Entities {
8789 Entities : []params.Entity {{Tag : "unit-mysql-0" }},
8890 })
@@ -97,7 +99,74 @@ func (s *storageSuite) TestWatchStorageAttachments(c *gc.C) {
9799 })
98100
99101 st := uniter .NewState (apiCaller , names .NewUnitTag ("mysql/0" ))
100- _ , err := st .WatchStorageAttachments (names .NewUnitTag ("mysql/0" ))
102+ _ , err := st .WatchUnitStorageAttachments (names .NewUnitTag ("mysql/0" ))
103+ c .Check (err , gc .ErrorMatches , "FAIL" )
104+ c .Check (called , jc .IsTrue )
105+ }
106+
107+ func (s * storageSuite ) TestWatchStorageAttachments (c * gc.C ) {
108+ var called bool
109+ apiCaller := testing .APICallerFunc (func (objType string , version int , id , request string , arg , result interface {}) error {
110+ c .Check (objType , gc .Equals , "Uniter" )
111+ c .Check (version , gc .Equals , 2 )
112+ c .Check (id , gc .Equals , "" )
113+ c .Check (request , gc .Equals , "WatchStorageAttachments" )
114+ c .Check (arg , gc .DeepEquals , params.StorageAttachmentIds {
115+ Ids : []params.StorageAttachmentId {{
116+ StorageTag : "storage-data-0" ,
117+ UnitTag : "unit-mysql-0" ,
118+ }},
119+ })
120+ c .Assert (result , gc .FitsTypeOf , & params.NotifyWatchResults {})
121+ * (result .(* params.NotifyWatchResults )) = params.NotifyWatchResults {
122+ Results : []params.NotifyWatchResult {{
123+ Error : & params.Error {Message : "FAIL" },
124+ }},
125+ }
126+ called = true
127+ return nil
128+ })
129+
130+ st := uniter .NewState (apiCaller , names .NewUnitTag ("mysql/0" ))
131+ _ , err := st .WatchStorageAttachment (names .NewStorageTag ("data/0" ), names .NewUnitTag ("mysql/0" ))
101132 c .Check (err , gc .ErrorMatches , "FAIL" )
102133 c .Check (called , jc .IsTrue )
103134}
135+
136+ func (s * storageSuite ) TestStorageAttachments (c * gc.C ) {
137+ storageAttachment := params.StorageAttachment {
138+ StorageTag : "storage-whatever-0" ,
139+ OwnerTag : "service-mysql" ,
140+ UnitTag : "unit-mysql-0" ,
141+ Kind : params .StorageKindBlock ,
142+ Location : "/dev/sda" ,
143+ }
144+
145+ var called bool
146+ apiCaller := testing .APICallerFunc (func (objType string , version int , id , request string , arg , result interface {}) error {
147+ c .Check (objType , gc .Equals , "Uniter" )
148+ c .Check (version , gc .Equals , 2 )
149+ c .Check (id , gc .Equals , "" )
150+ c .Check (request , gc .Equals , "StorageAttachments" )
151+ c .Check (arg , gc .DeepEquals , params.StorageAttachmentIds {
152+ Ids : []params.StorageAttachmentId {{
153+ StorageTag : "storage-data-0" ,
154+ UnitTag : "unit-mysql-0" ,
155+ }},
156+ })
157+ c .Assert (result , gc .FitsTypeOf , & params.StorageAttachmentResults {})
158+ * (result .(* params.StorageAttachmentResults )) = params.StorageAttachmentResults {
159+ Results : []params.StorageAttachmentResult {{
160+ Result : storageAttachment ,
161+ }},
162+ }
163+ called = true
164+ return nil
165+ })
166+
167+ st := uniter .NewState (apiCaller , names .NewUnitTag ("mysql/0" ))
168+ attachment , err := st .StorageAttachment (names .NewStorageTag ("data/0" ), names .NewUnitTag ("mysql/0" ))
169+ c .Check (err , jc .ErrorIsNil )
170+ c .Check (called , jc .IsTrue )
171+ c .Assert (attachment , gc .DeepEquals , storageAttachment )
172+ }
0 commit comments