A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat: add tag common repo unit test
LinkinStar3a2c8700c9a9
diff --git a/Dockerfile b/Dockerfileindex c1bd53ba..2cbe7a6d 100644--- a/Dockerfile+++ b/Dockerfile@@ -26,7 +26,7 @@ COPY . ${BUILD_DIR}WORKDIR ${BUILD_DIR}COPY --from=node-builder /tmp/build ${BUILD_DIR}/ui/buildRUN apk --no-cache add build-base git \- && make clean build \+ && make clean test build \&& cp answer /usr/bin/answerRUN mkdir -p /data/uploads && chmod 777 /data/uploads \diff --git a/Makefile b/Makefileindex f98526b7..1ecff1c9 100644--- a/Makefile+++ b/Makefile@@ -26,7 +26,7 @@ generate:go mod tidytest:- @$(GO) test ./...+ @$(GO) test ./internal/repo/repo_test# clean all build resultclean:diff --git a/internal/repo/repo_test/tag_repo_test.go b/internal/repo/repo_test/tag_repo_test.goindex 9c2e012a..d659651c 100644--- a/internal/repo/repo_test/tag_repo_test.go+++ b/internal/repo/repo_test/tag_repo_test.go@@ -8,6 +8,7 @@ import ("github.com/answerdev/answer/internal/entity""github.com/answerdev/answer/internal/repo/tag"+ "github.com/answerdev/answer/internal/repo/tag_common""github.com/answerdev/answer/internal/repo/unique""github.com/answerdev/answer/pkg/converter""github.com/stretchr/testify/assert"@@ -42,8 +43,8 @@ var (func addTagList() {uniqueIDRepo := unique.NewUniqueIDRepo(testDataSource)- tagRepo := tag.NewTagRepo(testDataSource, uniqueIDRepo)- err := tagRepo.AddTagList(context.TODO(), testTagList)+ tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, uniqueIDRepo)+ err := tagCommonRepo.AddTagList(context.TODO(), testTagList)if err != nil {panic(err)}@@ -51,9 +52,9 @@ func addTagList() {func Test_tagRepo_GetTagByID(t *testing.T) {tagOnce.Do(addTagList)- tagRepo := tag.NewTagRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))+ tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))- gotTag, exist, err := tagRepo.GetTagByID(context.TODO(), testTagList[0].ID)+ gotTag, exist, err := tagCommonRepo.GetTagByID(context.TODO(), testTagList[0].ID)assert.NoError(t, err)assert.True(t, exist)assert.Equal(t, testTagList[0].SlugName, gotTag.SlugName)@@ -61,9 +62,9 @@ func Test_tagRepo_GetTagByID(t *testing.T) {func Test_tagRepo_GetTagBySlugName(t *testing.T) {tagOnce.Do(addTagList)- tagRepo := tag.NewTagRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))+ tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))- gotTag, exist, err := tagRepo.GetTagBySlugName(context.TODO(), testTagList[0].SlugName)+ gotTag, exist, err := tagCommonRepo.GetTagBySlugName(context.TODO(), testTagList[0].SlugName)assert.NoError(t, err)assert.True(t, exist)assert.Equal(t, testTagList[0].SlugName, gotTag.SlugName)@@ -80,36 +81,36 @@ func Test_tagRepo_GetTagList(t *testing.T) {func Test_tagRepo_GetTagListByIDs(t *testing.T) {tagOnce.Do(addTagList)- tagRepo := tag.NewTagRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))+ tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))- gotTags, err := tagRepo.GetTagListByIDs(context.TODO(), []string{testTagList[0].ID})+ gotTags, err := tagCommonRepo.GetTagListByIDs(context.TODO(), []string{testTagList[0].ID})assert.NoError(t, err)assert.Equal(t, testTagList[0].SlugName, gotTags[0].SlugName)}func Test_tagRepo_GetTagListByName(t *testing.T) {tagOnce.Do(addTagList)- tagRepo := tag.NewTagRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))+ tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))- gotTags, err := tagRepo.GetTagListByName(context.TODO(), testTagList[0].SlugName, 1)+ gotTags, err := tagCommonRepo.GetTagListByName(context.TODO(), testTagList[0].SlugName, 1, false)assert.NoError(t, err)assert.Equal(t, testTagList[0].SlugName, gotTags[0].SlugName)}func Test_tagRepo_GetTagListByNames(t *testing.T) {tagOnce.Do(addTagList)- tagRepo := tag.NewTagRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))+ tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))- gotTags, err := tagRepo.GetTagListByNames(context.TODO(), []string{testTagList[0].SlugName})+ gotTags, err := tagCommonRepo.GetTagListByNames(context.TODO(), []string{testTagList[0].SlugName})assert.NoError(t, err)assert.Equal(t, testTagList[0].SlugName, gotTags[0].SlugName)}func Test_tagRepo_GetTagPage(t *testing.T) {tagOnce.Do(addTagList)- tagRepo := tag.NewTagRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))+ tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))- gotTags, _, err := tagRepo.GetTagPage(context.TODO(), 1, 1, &entity.Tag{SlugName: testTagList[0].SlugName}, "")+ gotTags, _, err := tagCommonRepo.GetTagPage(context.TODO(), 1, 1, &entity.Tag{SlugName: testTagList[0].SlugName}, "")assert.NoError(t, err)assert.Equal(t, testTagList[0].SlugName, gotTags[0].SlugName)}@@ -121,7 +122,9 @@ func Test_tagRepo_RemoveTag(t *testing.T) {err := tagRepo.RemoveTag(context.TODO(), testTagList[1].ID)assert.NoError(t, err)- _, exist, err := tagRepo.GetTagBySlugName(context.TODO(), testTagList[1].SlugName)+ tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))++ _, exist, err := tagCommonRepo.GetTagBySlugName(context.TODO(), testTagList[1].SlugName)assert.NoError(t, err)assert.False(t, exist)}@@ -134,21 +137,22 @@ func Test_tagRepo_UpdateTag(t *testing.T) {err := tagRepo.UpdateTag(context.TODO(), testTagList[0])assert.NoError(t, err)- gotTag, exist, err := tagRepo.GetTagByID(context.TODO(), testTagList[0].ID)+ tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))++ gotTag, exist, err := tagCommonRepo.GetTagByID(context.TODO(), testTagList[0].ID)assert.NoError(t, err)assert.True(t, exist)assert.Equal(t, testTagList[0].DisplayName, gotTag.DisplayName)}func Test_tagRepo_UpdateTagQuestionCount(t *testing.T) {- uniqueIDRepo := unique.NewUniqueIDRepo(testDataSource)- tagRepo := tag.NewTagRepo(testDataSource, uniqueIDRepo)+ tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))testTagList[0].DisplayName = "golang"- err := tagRepo.UpdateTagQuestionCount(context.TODO(), testTagList[0].ID, 100)+ err := tagCommonRepo.UpdateTagQuestionCount(context.TODO(), testTagList[0].ID, 100)assert.NoError(t, err)- gotTag, exist, err := tagRepo.GetTagByID(context.TODO(), testTagList[0].ID)+ gotTag, exist, err := tagCommonRepo.GetTagByID(context.TODO(), testTagList[0].ID)assert.NoError(t, err)assert.True(t, exist)assert.Equal(t, 100, gotTag.QuestionCount)@@ -166,7 +170,9 @@ func Test_tagRepo_UpdateTagSynonym(t *testing.T) {converter.StringToInt64(testTagList[0].ID), testTagList[0].SlugName)assert.NoError(t, err)- gotTag, exist, err := tagRepo.GetTagByID(context.TODO(), testTagList[2].ID)+ tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))++ gotTag, exist, err := tagCommonRepo.GetTagByID(context.TODO(), testTagList[2].ID)assert.NoError(t, err)assert.True(t, exist)assert.Equal(t, testTagList[0].ID, fmt.Sprintf("%d", gotTag.MainTagID))