Skip to content

Commit

Permalink
test: ensure if battle not exist GetBattle() will return nil; ensure …
Browse files Browse the repository at this point in the history
…if game is not exists GetGame() will return nil;
  • Loading branch information
riandyrn committed Jul 18, 2024
1 parent 130d7ae commit 673b37e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions internal/driven/storage/memory/battlestrg/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ func TestSaveGetBattle(t *testing.T) {
strg := battlestrg.New()
expBattle := newBattle()

// get battle, supposedly the returned battle is nil
battle, err := strg.GetBattle(context.Background(), expBattle.GameID)
require.NoError(t, err)
require.Nil(t, battle, "battle is not nil")

// save battle
err := strg.SaveBattle(context.Background(), *expBattle)
err = strg.SaveBattle(context.Background(), *expBattle)
require.NoError(t, err)

// get battle
battle, err := strg.GetBattle(context.Background(), expBattle.GameID)
battle, err = strg.GetBattle(context.Background(), expBattle.GameID)
require.NoError(t, err)

// ensure battle is equal to expBattle
Expand Down
9 changes: 7 additions & 2 deletions internal/driven/storage/memory/gamestrg/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ func TestSaveGetGame(t *testing.T) {
strg := gamestrg.New()
expGame := initNewGame()

// get game, supposedly the returned game is nil
game, err := strg.GetGame(context.Background(), expGame.ID)
require.NoError(t, err)
require.Nil(t, game, "game is not nil")

// save game
err := strg.SaveGame(context.Background(), *expGame)
err = strg.SaveGame(context.Background(), *expGame)
require.NoError(t, err)

// get game
game, err := strg.GetGame(context.Background(), expGame.ID)
game, err = strg.GetGame(context.Background(), expGame.ID)
require.NoError(t, err)

// ensure game is equal to newGame
Expand Down

0 comments on commit 673b37e

Please sign in to comment.