Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repositoryのテストの書き方を統一する #682

Open
ras0q opened this issue Jun 18, 2024 · 0 comments
Open

repositoryのテストの書き方を統一する #682

ras0q opened this issue Jun 18, 2024 · 0 comments

Comments

@ras0q
Copy link
Member

ras0q commented Jun 18, 2024

無理にTable Driven Testにせずに順にステップを踏む
mockdataは使わずにテスト内で作ったデータを挿入する
externalのmockはgomockを使い必要であれば動作を定義する

func TestGetContests(t *testing.T) {
	t.Parallel()

	db := SetupTestGormDB(t)
	ctrl := gomock.NewController(t)
	repo := NewContestRepository(db, mock_external.NewMockPortalAPI(ctrl))

	contest1, err := repo.CreateContest(context.Background(), randomContestArgs())
	assert.NoError(t, err)
	contest2, err := repo.CreateContest(context.Background(), randomContestArgs())
	assert.NoError(t, err)

	t.Run("success", func(t *testing.T) {
		actualContests, err := repo.GetContests(context.Background())
		assert.NoError(t, err)

		expectedContests := []*domain.Contest{&contest1.Contest, &contest2.Contest}
		assert.ElementsMatch(t, expectedContests, actualContests)
	})

	// t.Run("...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant