func TestGetAllCombinedAppStorageByAccountId(t *testing.T) { db := modeltesthelper.NewMongoDB(t) defer db.Close() acc := createTestAccount(t) cs1 := &models.CombinedAppStorage{ Id: bson.NewObjectId(), AccountId: acc.Id, } cs2 := &models.CombinedAppStorage{ Id: bson.NewObjectId(), AccountId: acc.Id, } if err := modelhelper.CreateCombinedAppStorage(cs1); err != nil { t.Fatalf("error should be nil but got:", err) } if err := modelhelper.CreateCombinedAppStorage(cs2); err != nil { t.Fatalf("error should be nil but got:", err) } if cs1 == nil { t.Fatal("CombinedAppStorage should not be nil") } if cs1.AccountId != acc.Id { t.Fatalf("CombinedAppStorage Account id should equal: but got:", acc.Id, cs1.AccountId) } css, err := modelhelper.GetAllCombinedAppStorageByAccountId(acc.Id) if err != nil { t.Fatalf("error should be nil but got:", err) } if len(css) != 2 { t.Fatalf("length of CombinedAppStorage should equal to 2, but got:", len(css)) } }
func deleteCombinedAppStorages(res interface{}) error { cs := res.(*models.CombinedAppStorage) if getAccountByID(cs.AccountId.Hex()) { storages, err := helper.GetAllCombinedAppStorageByAccountId(cs.AccountId) if err != nil { return err } if len(storages) > 1 { mergedStorage := mergeCombinedAppStorageData(storages) _, err := combineWithDeletion(mergedStorage, storages) if err != nil { return err } } return nil } fmt.Printf("deleting CombinedAppStorage %q\n", cs.Id) if !*flagDry { return helper.RemoveCombinedAppStorage(cs.Id) } return nil }