Skip to content

Commit

Permalink
TestEndorserRepository.Get()
Browse files Browse the repository at this point in the history
  • Loading branch information
emacsway committed May 28, 2024
1 parent 8d5c04c commit 007a07d
Showing 1 changed file with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func TestEndorserRepository(t *testing.T) {
t.Parallel()
clearable(testInsert)(t, ro)
})

t.Run("testGet", func(t *testing.T) {
t.Parallel()
clearable(testGet)(t, ro)
})
})
}
}
Expand All @@ -52,8 +57,8 @@ func clearable(callable testCase) testCase {
}

func testInsert(t *testing.T, repositoryOption RepositoryOption) {
var exporterExpected endorser.EndorserExporter
var exporterActual endorser.EndorserExporter
var exporterRead endorser.EndorserExporter
factory := endorser.NewEndorserFaker(
endorser.WithTenantId(repositoryOption.TenantId),
endorser.WithMemberId(repositoryOption.MemberId),
Expand All @@ -62,17 +67,40 @@ func testInsert(t *testing.T, repositoryOption RepositoryOption) {
require.NoError(t, err)
err = repositoryOption.Repository.Insert(agg)
require.NoError(t, err)
agg.Export(&exporterActual)
agg.Export(&exporterExpected)

id, err := memberVal.NewMemberId(
uint(exporterActual.Id.TenantId),
uint(exporterActual.Id.MemberId),
uint(exporterExpected.Id.TenantId),
uint(exporterExpected.Id.MemberId),
)
require.NoError(t, err)
aggRead, err := repositoryOption.Repository.Get(id)
require.NoError(t, err)
aggRead.Export(&exporterRead)
assert.Equal(t, exporterActual, exporterRead)
aggRead.Export(&exporterActual)
assert.Equal(t, exporterExpected, exporterActual)
}

func testGet(t *testing.T, repositoryOption RepositoryOption) {
var exporterExpected endorser.EndorserExporter
var exporterActual endorser.EndorserExporter
factory := NewEndorserFaker(
repositoryOption.Session,
)
factory.BuildDependencies()

Check failure on line 89 in grade/internal/infrastructure/repositories/endorser/endorser_repository_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `factory.BuildDependencies` is not checked (errcheck)
aggExpected, err := factory.Create()
require.NoError(t, err)
aggExpected.Export(&exporterExpected)
assert.Greater(t, int(exporterExpected.Id.MemberId), 0)

id, err := memberVal.NewMemberId(
uint(exporterExpected.Id.TenantId),
uint(exporterExpected.Id.MemberId),
)
require.NoError(t, err)
aggActual, err := repositoryOption.Repository.Get(id)
require.NoError(t, err)
aggActual.Export(&exporterActual)
assert.Equal(t, exporterExpected, exporterActual)
}

type RepositoryOption struct {
Expand Down

0 comments on commit 007a07d

Please sign in to comment.