feat: add captcha repo unit test

This commit is contained in:
LinkinStar 2022-10-26 17:14:36 +08:00
parent 6f1e8b6aa9
commit 7af6db7c7f
1 changed files with 39 additions and 0 deletions

View File

@ -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)
}