@@ -350,6 +350,96 @@ func TestUpdateFileShareSnapshot(t *testing.T) {
350350 assertTestResult (t , & output , & expected )
351351 })
352352
353+ t .Run ("Should return 400 empty snapshot name is not allowed" , func (t * testing.T ) {
354+ var jsonStr = []byte (`{
355+ "name":"",
356+ "description":"fake snapshot"
357+ }` )
358+ snapshot := model.FileShareSnapshotSpec {BaseModel : & model.BaseModel {}}
359+ json .NewDecoder (bytes .NewBuffer (jsonStr )).Decode (& snapshot )
360+ mockClient := new (dbtest.Client )
361+ mockClient .On ("UpdateFileShareSnapshot" , c .NewAdminContext (), snapshot .Id , & snapshot ).
362+ Return (& expected , nil )
363+ db .C = mockClient
364+
365+ r , _ := http .NewRequest ("PUT" , "/v1beta/file/snapshots/3769855c-a102-11e7-b772-17b880d2f537" , bytes .NewBuffer (jsonStr ))
366+ w := httptest .NewRecorder ()
367+ r .Header .Set ("Content-Type" , "application/JSON" )
368+ beego .InsertFilter ("*" , beego .BeforeExec , func (httpCtx * context.Context ) {
369+ httpCtx .Input .SetData ("context" , c .NewAdminContext ())
370+ })
371+ beego .BeeApp .Handlers .ServeHTTP (w , r )
372+ assertTestResult (t , w .Code , 400 )
373+ })
374+
375+ t .Run ("Should return 400 snapshot name length should not be more than 255 characters" , func (t * testing.T ) {
376+ var jsonStr = []byte (`{
377+ "name": "BpLnfgDsc2WD8F2qNfHK5a84jjJkwzDkh9h2fhfUVuS9jZ8uVbhV3vC5AWX39IVUWSP2NcHciWvqZTa2N95RxRTZHWUsaD6HEdz0ThbXfQ6pYSQ3n267l1VQKGNbSuJE9fQbzONJAAwdCxmM8BIabKERsUhPNmMmdf2eSJyYtqwcFiUILzXv2fcNIrWO7sToFgoilA0U1WxNeW1gdgUVDsEWJ77aX7tLFJ84qYU6UrN8ctecwZt5S4zjhD0tXRTmkY",
378+ "description":"fake snapshot"
379+ }` )
380+ snapshot := model.FileShareSnapshotSpec {BaseModel : & model.BaseModel {}}
381+ json .NewDecoder (bytes .NewBuffer (jsonStr )).Decode (& snapshot )
382+ mockClient := new (dbtest.Client )
383+ mockClient .On ("UpdateFileShareSnapshot" , c .NewAdminContext (), snapshot .Id , & snapshot ).
384+ Return (& expected , nil )
385+ db .C = mockClient
386+
387+ r , _ := http .NewRequest ("PUT" , "/v1beta/file/snapshots/3769855c-a102-11e7-b772-17b880d2f537" , bytes .NewBuffer (jsonStr ))
388+ w := httptest .NewRecorder ()
389+ r .Header .Set ("Content-Type" , "application/JSON" )
390+ beego .InsertFilter ("*" , beego .BeforeExec , func (httpCtx * context.Context ) {
391+ httpCtx .Input .SetData ("context" , c .NewAdminContext ())
392+ })
393+ beego .BeeApp .Handlers .ServeHTTP (w , r )
394+ assertTestResult (t , w .Code , 400 )
395+ })
396+
397+ t .Run ("Should return 400 invalid snapshot name because it has some special characters" , func (t * testing.T ) {
398+ var jsonStr = []byte (`{
399+ "name": "#Snap !$!test",
400+ "description":"fake snapshot"
401+ }` )
402+ snapshot := model.FileShareSnapshotSpec {BaseModel : & model.BaseModel {}}
403+ json .NewDecoder (bytes .NewBuffer (jsonStr )).Decode (& snapshot )
404+
405+ mockClient := new (dbtest.Client )
406+ mockClient .On ("UpdateFileShareSnapshot" , c .NewAdminContext (), snapshot .Id , & snapshot ).
407+ Return (& expected , nil )
408+ db .C = mockClient
409+
410+ r , _ := http .NewRequest ("PUT" , "/v1beta/file/snapshots/3769855c-a102-11e7-b772-17b880d2f537" , bytes .NewBuffer (jsonStr ))
411+ w := httptest .NewRecorder ()
412+ r .Header .Set ("Content-Type" , "application/JSON" )
413+ beego .InsertFilter ("*" , beego .BeforeExec , func (httpCtx * context.Context ) {
414+ httpCtx .Input .SetData ("context" , c .NewAdminContext ())
415+ })
416+ beego .BeeApp .Handlers .ServeHTTP (w , r )
417+ assertTestResult (t , w .Code , 400 )
418+ })
419+
420+ t .Run ("Should return 400 invalid snapshot description and it has some special characters" , func (t * testing.T ) {
421+ var jsonStr = []byte (`{
422+ "name":"fake snapshot",
423+ "description": "#Share !$!test"
424+ }` )
425+ snapshot := model.FileShareSnapshotSpec {BaseModel : & model.BaseModel {}}
426+ json .NewDecoder (bytes .NewBuffer (jsonStr )).Decode (& snapshot )
427+
428+ mockClient := new (dbtest.Client )
429+ mockClient .On ("UpdateFileShareSnapshot" , c .NewAdminContext (), snapshot .Id , & snapshot ).
430+ Return (& expected , nil )
431+ db .C = mockClient
432+
433+ r , _ := http .NewRequest ("PUT" , "/v1beta/file/snapshots/3769855c-a102-11e7-b772-17b880d2f537" , bytes .NewBuffer (jsonStr ))
434+ w := httptest .NewRecorder ()
435+ r .Header .Set ("Content-Type" , "application/JSON" )
436+ beego .InsertFilter ("*" , beego .BeforeExec , func (httpCtx * context.Context ) {
437+ httpCtx .Input .SetData ("context" , c .NewAdminContext ())
438+ })
439+ beego .BeeApp .Handlers .ServeHTTP (w , r )
440+ assertTestResult (t , w .Code , 400 )
441+ })
442+
353443 t .Run ("Should return 500 if update fileshare snapshot with bad request" , func (t * testing.T ) {
354444 snapshot := model.FileShareSnapshotSpec {BaseModel : & model.BaseModel {}}
355445 json .NewDecoder (bytes .NewBuffer (jsonStr )).Decode (& snapshot )
0 commit comments