Skip to content

Commit

Permalink
chore: delete 1 test case
Browse files Browse the repository at this point in the history
  • Loading branch information
vankongv committed Sep 10, 2024
1 parent 512b0f1 commit 3e7d7f6
Showing 1 changed file with 18 additions and 41 deletions.
59 changes: 18 additions & 41 deletions tests/delete_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ type userKeys struct {
}

type testCase struct {
title string
itemsToDelete []userKeys
itemsLeft int
seedData []tableRecord
title string
itemsToDelete []userKeys
expectedItemsLeft int
seedData []tableRecord
}

func TestDeleteItem(t *testing.T) {
Expand Down Expand Up @@ -75,53 +75,30 @@ func TestDeleteItem(t *testing.T) {
Sk: "user#2",
},
},
itemsLeft: 3,
seedData: records, //each test case will have the same seed data
expectedItemsLeft: 3,
seedData: records, //each test case will have the same seed data
},
{
title: "Delete all users",
itemsToDelete: []userKeys{
{
Pk: "users#org1",
Sk: "user#1",
},
{
Pk: "users#org1",
Sk: "user#2",
},
{
Pk: "users#org1",
Sk: "user#3",
},
{
Pk: "users#org2",
Sk: "user#4",
},
},
itemsLeft: 0,
seedData: records,
},
{
title: "Delete wrong user",
title: "Delete item with wrong sk",
itemsToDelete: []userKeys{
{
Pk: "users#org1",
Sk: "user#none",
},
},
itemsLeft: 4,
seedData: records,
expectedItemsLeft: 4,
seedData: records,
},
{
title: "Delete user with invalid keys",
title: "Delete item with wrong pk and sk",
itemsToDelete: []userKeys{
{
Pk: "invalid#org",
Sk: "invalid#user",
},
},
itemsLeft: 4,
seedData: records,
expectedItemsLeft: 4,
seedData: records,
},
}

Expand Down Expand Up @@ -150,16 +127,16 @@ func TestDeleteItem(t *testing.T) {
})
}

var out []tableRecord
var remainingItems []tableRecord

err = table.BatchGetItems(ctx, itemsToGet, &out)
err = table.BatchGetItems(ctx, itemsToGet, &remainingItems)
if err != nil {
t.Fatalf("Unable to get seed data: %s", err)
}

//check if deleted items are not in db
dataKeys := make([]string, 0, len(out))
for _, item := range out {
dataKeys := make([]string, 0, len(remainingItems))
for _, item := range remainingItems {
dataKeys = append(dataKeys, fmt.Sprintf("%s--%s", item.Pk, item.Sk))
}

Expand All @@ -171,8 +148,8 @@ func TestDeleteItem(t *testing.T) {
}

//check if remaining records match expected number of items left
if len(out) != c.itemsLeft {
t.Fatalf("expected items in db; %v found; %v", c.itemsLeft, len(out))
if len(remainingItems) != c.expectedItemsLeft {
t.Fatalf("expected items in db; %v found; %v", c.expectedItemsLeft, len(remainingItems))
}
})
}
Expand Down

0 comments on commit 3e7d7f6

Please sign in to comment.