From b779448fcddd67c89a6286a74c9485327961e405 Mon Sep 17 00:00:00 2001 From: Weilin Shi <934587911@qq.com> Date: Wed, 20 Sep 2017 09:51:27 +0800 Subject: [PATCH] update: improve coverage --- README.md | 2 +- captcha_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f10a195..6b46620 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ > Package captcha provides a simple API for captcha generation -
+
[![GoDoc](https://godoc.org/github.com/steambap/captcha?status.svg)](https://godoc.org/github.com/steambap/captcha) [![Build Status](https://travis-ci.org/steambap/captcha.svg)](https://travis-ci.org/steambap/captcha) diff --git a/captcha_test.go b/captcha_test.go index bb53049..0f1d3d1 100644 --- a/captcha_test.go +++ b/captcha_test.go @@ -2,10 +2,12 @@ package captcha import ( "bytes" + "image/color" "testing" ) func TestNewCaptcha(t *testing.T) { + New(36, 12) data, err := New(150, 50) if err != nil { t.Fatal(err) @@ -13,3 +15,24 @@ func TestNewCaptcha(t *testing.T) { buf := new(bytes.Buffer) data.WriteTo(buf) } + +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 +}