This repository has been archived on 2024-08-25. You can view files and clone it, but cannot push or open issues or pull requests.
captcha/captcha_test.go

52 lines
897 B
Go
Raw Normal View History

2017-09-19 12:17:25 +01:00
package captcha
import (
"bytes"
2017-09-22 03:01:40 +01:00
"golang.org/x/image/font/gofont/goregular"
2017-09-20 02:51:27 +01:00
"image/color"
2017-09-19 12:17:25 +01:00
"testing"
)
func TestNewCaptcha(t *testing.T) {
2017-09-20 02:51:27 +01:00
New(36, 12)
2017-09-19 12:17:25 +01:00
data, err := New(150, 50)
if err != nil {
t.Fatal(err)
}
buf := new(bytes.Buffer)
data.WriteTo(buf)
}
2017-09-20 02:51:27 +01:00
func TestNewCaptchaOptions(t *testing.T) {
New(100, 34, func(options *Options) {
options.BackgroundColor = color.Opaque
options.CharPreset = "1234567890"
options.CurveNumber = 0
options.TextLength = 6
})
}
func TestCovNilFontError(t *testing.T) {
temp := ttfFont
ttfFont = nil
_, err := New(150, 50)
if err == nil {
t.Fatal("Expect to get nil font error")
}
ttfFont = temp
}
2017-09-22 03:01:40 +01:00
func TestLoadFont(t *testing.T) {
err := LoadFont(goregular.TTF)
if err != nil {
t.Fatal("Fail to load go font")
}
err = LoadFont([]byte("invalid"))
if err == nil {
t.Fatal("LoadFont incorrecly parse an invalid font")
}
}