@@ -2,6 +2,7 @@ package test
22
33import (
44 "fmt"
5+ "strconv"
56 "testing"
67 "time"
78
@@ -209,6 +210,77 @@ func (suite *syncContainerTestSuite) TestGetContainerContentsDirsWithAllAttrs()
209210 }
210211}
211212
213+ func (suite * syncContainerTestSuite ) TestSetDirsAttrs () {
214+ path := fmt .Sprintf ("tmp/test/sync_test/TestSetDirsAttrs/%d/" , time .Now ().Unix ())
215+
216+ // create empty directory
217+ putObjectInput := & v3io.PutObjectInput {}
218+ putObjectInput .Path = fmt .Sprintf ("%sdir-test/" , path )
219+ putObjectInput .Body = nil
220+
221+ // when run against a context
222+ suite .populateDataPlaneInput (& putObjectInput .DataPlaneInput )
223+ err := suite .container .PutObjectSync (putObjectInput )
224+ suite .Require ().NoError (err , "Failed to create test directory" )
225+
226+ // Update directory's attributes
227+ updateObjectInput := & v3io.UpdateObjectInput {}
228+ updateObjectInput .Path = fmt .Sprintf ("%sdir-test/" , path )
229+ layout := "2006-01-02T15:04:05.00Z"
230+ atime , err := time .Parse (layout , "2020-11-22T19:27:33.49Z" )
231+ suite .Require ().NoError (err )
232+ ctime , err := time .Parse (layout , "2020-09-20T15:10:35.08Z" )
233+ suite .Require ().NoError (err )
234+ mtime , err := time .Parse (layout , "2020-09-24T12:55:35.08Z" )
235+ suite .Require ().NoError (err )
236+ dirAttributes := & v3io.DirAttributes {
237+ Mode : 511 ,
238+ UID : 67 ,
239+ GID : 68 ,
240+ AtimeSec : int (atime .Unix ()),
241+ AtimeNSec : int (atime .UnixNano () % 1000000000 ),
242+ CtimeSec : int (ctime .Unix ()),
243+ CtimeNSec : int (ctime .UnixNano () % 1000000000 ),
244+ MtimeSec : int (mtime .Unix ()),
245+ MtimeNSec : int (mtime .UnixNano () % 1000000000 ),
246+ }
247+ updateObjectInput .DirAttributes = dirAttributes
248+
249+ // when run against a context
250+ suite .populateDataPlaneInput (& updateObjectInput .DataPlaneInput )
251+ err = suite .container .UpdateObjectSync (updateObjectInput )
252+ suite .Require ().NoError (err , "Failed to update test directory" )
253+
254+ // Read directory and compare attributes
255+ getContainerContentsInput := v3io.GetContainerContentsInput {
256+ Path : path ,
257+ GetAllAttributes : true ,
258+ DirectoriesOnly : true ,
259+ Limit : 10 ,
260+ }
261+
262+ // when run against a context
263+ suite .populateDataPlaneInput (& getContainerContentsInput .DataPlaneInput )
264+
265+ // get container contents
266+ response , err := suite .container .GetContainerContentsSync (& getContainerContentsInput )
267+ suite .Require ().NoError (err , "Failed to get container contents" )
268+ response .Release ()
269+
270+ getContainerContentsOutput := response .Output .(* v3io.GetContainerContentsOutput )
271+ suite .Require ().Empty (len (getContainerContentsOutput .Contents ))
272+ suite .Require ().Equal (1 , len (getContainerContentsOutput .CommonPrefixes ))
273+ suite .Require ().Equal (false , getContainerContentsOutput .IsTruncated )
274+
275+ prefix := getContainerContentsOutput .CommonPrefixes [0 ]
276+ suite .Require ().Equal (atime .Format (layout ), prefix .AccessTime )
277+ suite .Require ().Equal (mtime .Format (layout ), prefix .LastModified )
278+ suite .Require ().Equal (ctime .Format (layout ), prefix .CreatingTime )
279+ suite .Require ().Equal (strconv .FormatInt (int64 (dirAttributes .GID ), 16 ), prefix .GID )
280+ suite .Require ().Equal (strconv .FormatInt (int64 (dirAttributes .UID ), 16 ), prefix .UID )
281+ suite .Require ().Equal ("040777" , string (prefix .Mode ))
282+ }
283+
212284type syncContextContainerTestSuite struct {
213285 syncContainerTestSuite
214286}
0 commit comments