@@ -396,38 +396,62 @@ func Test_defaultResourceConfig(t *testing.T) {
396
396
}
397
397
}
398
398
399
- // TODO We need to turn this ut on after adding the delete portal to the UI
400
- // func TestDeleteProjectWhenAddonExists(t *testing.T) {
401
- // db := &dao.DBClient{}
402
- // monkey.PatchInstanceMethod(reflect.TypeOf(db), "GetApplicationCountByProjectID",
403
- // func(*dao.DBClient, int64) (int64, error) {
404
- // return 0, nil
405
- // })
406
- // defer monkey.UnpatchAll()
407
-
408
- // monkey.PatchInstanceMethod(reflect.TypeOf(db), "GetProjectByID",
409
- // func(*dao.DBClient, int64) (model.Project, error) {
410
- // return model.Project{}, nil
411
- // })
412
-
413
- // bdl := &bundle.Bundle{}
414
- // monkey.PatchInstanceMethod(reflect.TypeOf(bdl), "ListAddonByProjectID",
415
- // func(*bundle.Bundle, int64, int64) (*apistructs.AddonListResponse, error) {
416
- // return &apistructs.AddonListResponse{
417
- // Header: apistructs.Header{},
418
- // Data: []apistructs.AddonFetchResponseData{
419
- // {
420
- // ID: "1",
421
- // },
422
- // },
423
- // }, nil
424
- // })
425
- // p := &Project{}
426
- // _, err := p.Delete(1)
427
- // if err == nil {
428
- // assert.Fail(t, "fail")
429
- // return
430
- // }
431
- // assert.Equal(t, "failed to delete project(there exists addons)", err.Error())
432
-
433
- // }
399
+ func TestDeleteProjectWhenAddonExists (t * testing.T ) {
400
+ db := & dao.DBClient {}
401
+ monkey .PatchInstanceMethod (reflect .TypeOf (db ), "GetApplicationCountByProjectID" ,
402
+ func (* dao.DBClient , int64 ) (int64 , error ) {
403
+ return 0 , nil
404
+ })
405
+ defer monkey .UnpatchAll ()
406
+
407
+ monkey .PatchInstanceMethod (reflect .TypeOf (db ), "GetProjectByID" ,
408
+ func (* dao.DBClient , int64 ) (model.Project , error ) {
409
+ return model.Project {}, nil
410
+ })
411
+
412
+ bdl := & bundle.Bundle {}
413
+ monkey .PatchInstanceMethod (reflect .TypeOf (bdl ), "ListAddonByProjectID" ,
414
+ func (* bundle.Bundle , int64 , int64 ) (* apistructs.AddonListResponse , error ) {
415
+ return & apistructs.AddonListResponse {
416
+ Header : apistructs.Header {},
417
+ Data : []apistructs.AddonFetchResponseData {
418
+ {
419
+ ID : "1" ,
420
+ PlatformServiceType : 1 ,
421
+ },
422
+ {
423
+ ID : "1" ,
424
+ PlatformServiceType : 0 ,
425
+ },
426
+ },
427
+ }, nil
428
+ })
429
+ p := & Project {}
430
+ _ , err := p .Delete (1 )
431
+ if err == nil {
432
+ assert .Fail (t , "fail" )
433
+ return
434
+ }
435
+ assert .Equal (t , "failed to delete project(there exists addons)" , err .Error ())
436
+ }
437
+
438
+ func TestAddOnsFilterIn (t * testing.T ) {
439
+ addOns := []apistructs.AddonFetchResponseData {
440
+ {
441
+ ID : "1" ,
442
+ PlatformServiceType : 1 ,
443
+ },
444
+ {
445
+ ID : "2" ,
446
+ PlatformServiceType : 0 ,
447
+ },
448
+ {
449
+ ID : "3" ,
450
+ PlatformServiceType : 1 ,
451
+ },
452
+ }
453
+ newAddOns := addOnsFilterIn (addOns , func (addOn * apistructs.AddonFetchResponseData ) bool {
454
+ return addOn .PlatformServiceType == 0
455
+ })
456
+ assert .Equal (t , 1 , len (newAddOns ))
457
+ }
0 commit comments