mirror of https://gitee.com/answerdev/answer.git
feat: add captcha repo unit test
This commit is contained in:
parent
6f1e8b6aa9
commit
7af6db7c7f
|
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue