Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
test: add Mongo Asset's Remove unit testing
Browse files Browse the repository at this point in the history
Signed-off-by: KeisukeYamashita <[email protected]>
  • Loading branch information
KeisukeYamashita committed May 10, 2022
1 parent 56a028d commit 4e9996e
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions internal/infrastructure/mongo/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/reearth/reearth-backend/pkg/asset"
"github.com/reearth/reearth-backend/pkg/id"
"github.com/reearth/reearth-backend/pkg/rerror"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -64,3 +65,55 @@ func TestFindByID(t *testing.T) {
})
}
}

func TestRemove(t *testing.T) {
tests := []struct {
Name string
Expected struct {
Name string
Asset *asset.Asset
}
}{
{
Expected: struct {
Name string
Asset *asset.Asset
}{
Asset: asset.New().
NewID().
CreatedAt(time.Now()).
Team(id.NewTeamID()).
Name("name").
Size(10).
URL("hxxps://https://reearth.io/").
ContentType("json").
MustBuild(),
},
},
}

initDB := connect(t)

for _, tc := range tests {
tc := tc

t.Run(tc.Name, func(t *testing.T) {
t.Parallel()

client, dropDB := initDB()
defer dropDB()

repo := NewAsset(client)
ctx := context.Background()
err := repo.Save(ctx, tc.Expected.Asset)
assert.NoError(t, err)

err = repo.Remove(ctx, tc.Expected.Asset.ID())
assert.NoError(t, err)

got, err := repo.FindByID(ctx, tc.Expected.Asset.ID())
assert.Equal(t, err, rerror.ErrNotFound)
assert.Nil(t, got)
})
}
}

0 comments on commit 4e9996e

Please sign in to comment.