update: do not panic in init function parse fail

update: extract test for small image from TestNewCaptcha
fix: typo in test
This commit is contained in:
Weilin Shi 2017-09-22 10:41:09 +08:00
parent 21cc8dcbcb
commit 66c7cdc2f4
2 changed files with 9 additions and 7 deletions

View File

@ -71,11 +71,7 @@ func (data *Data) WriteTo(w io.Writer) error {
} }
func init() { func init() {
var err error ttfFont, _ = freetype.ParseFont(ttf)
ttfFont, err = freetype.ParseFont(ttf)
if err != nil {
panic(err)
}
} }
// LoadFont let you load an external font // LoadFont let you load an external font

View File

@ -8,7 +8,6 @@ import (
) )
func TestNewCaptcha(t *testing.T) { func TestNewCaptcha(t *testing.T) {
New(36, 12)
data, err := New(150, 50) data, err := New(150, 50)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -17,6 +16,13 @@ func TestNewCaptcha(t *testing.T) {
data.WriteTo(buf) data.WriteTo(buf)
} }
func TestSmallCaptcha(t *testing.T) {
_, err := New(36, 12)
if err != nil {
t.Fatal(err)
}
}
func TestNewCaptchaOptions(t *testing.T) { func TestNewCaptchaOptions(t *testing.T) {
New(100, 34, func(options *Options) { New(100, 34, func(options *Options) {
options.BackgroundColor = color.Opaque options.BackgroundColor = color.Opaque
@ -46,6 +52,6 @@ func TestLoadFont(t *testing.T) {
err = LoadFont([]byte("invalid")) err = LoadFont([]byte("invalid"))
if err == nil { if err == nil {
t.Fatal("LoadFont incorrecly parse an invalid font") t.Fatal("LoadFont incorrectly parse an invalid font")
} }
} }