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 captcha repo unit test
LinkinStar7af6db7c7fb5
diff --git a/internal/repo/repo_test/captcha_test.go b/internal/repo/repo_test/captcha_test.gonew file mode 100644index 00000000..74353a8e--- /dev/null+++ b/internal/repo/repo_test/captcha_test.go@@ -0,0 +1,39 @@+package repo_test++import (+ "context"+ "testing"++ "github.com/answerdev/answer/internal/repo/captcha"+ "github.com/stretchr/testify/assert"+)++var (+ ip = "127.0.0.1"+ actionType = "actionType"+ amount = 1+)++func Test_captchaRepo_DelActionType(t *testing.T) {+ captchaRepo := captcha.NewCaptchaRepo(testDataSource)+ err := captchaRepo.SetActionType(context.TODO(), ip, actionType, amount)+ assert.NoError(t, err)++ gotAmount, err := captchaRepo.GetActionType(context.TODO(), ip, actionType)+ assert.NoError(t, err)+ assert.Equal(t, amount, gotAmount)++ err = captchaRepo.DelActionType(context.TODO(), ip, actionType)+ assert.NoError(t, err)+}++func Test_captchaRepo_SetCaptcha(t *testing.T) {+ captchaRepo := captcha.NewCaptchaRepo(testDataSource)+ key, capt := "key", "1234"+ err := captchaRepo.SetCaptcha(context.TODO(), key, capt)+ assert.NoError(t, err)++ gotCaptcha, err := captchaRepo.GetCaptcha(context.TODO(), key)+ assert.NoError(t, err)+ assert.Equal(t, capt, gotCaptcha)+}