Skip to content

Commit

Permalink
go Report fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mojocn committed May 9, 2019
1 parent a9969d3 commit dcf3942
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ examples/examples
goTestOutPutPng/*
ex
.codecov
coverage.*
coverage.*
*.exe
11 changes: 8 additions & 3 deletions captcha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ var configC = ConfigCharacter{

func TestGenerateCaptcha(t *testing.T) {
testDir, _ := ioutil.TempDir("", "")
defer os.Remove(testDir)

for idx, vv := range []interface{}{configA, configD} {

idkey, cap := GenerateCaptcha("", vv)
Expand All @@ -57,7 +59,7 @@ func TestGenerateCaptcha(t *testing.T) {

}
testDirAll, _ := ioutil.TempDir("", "all")

defer os.RemoveAll(testDirAll)
for i := 0; i < 16; i++ {
configC.Mode = i % 4
idkey, cap := GenerateCaptcha("", configC)
Expand Down Expand Up @@ -102,7 +104,7 @@ func TestVerifyCaptcha(t *testing.T) {
func TestPathExists(t *testing.T) {

testDir, _ := ioutil.TempDir("", "")

defer os.RemoveAll(testDir)
assert.True(t, pathExists(testDir))
assert.False(t, pathExists(testDir+"/NotExistFolder"))
}
Expand All @@ -111,6 +113,7 @@ func TestCaptchaWriteToFileCreateDirectory(t *testing.T) {

idKey, captcha := GenerateCaptcha("", configD)
testDir, _ := ioutil.TempDir("", "")
defer os.Remove(testDir)
assert.Nil(t, CaptchaWriteToFile(captcha, testDir+"/NotExistFolder", idKey, "png"))
}

Expand All @@ -119,13 +122,15 @@ func TestCaptchaWriteToFileCreateFileFailed(t *testing.T) {
var err error
idKey, captcha := GenerateCaptcha("", configD)
testDir, _ := ioutil.TempDir("", "")
defer os.Remove(testDir)
noPermissionDirPath := testDir + "/NoPermission"

err = os.Mkdir(noPermissionDirPath, os.ModeDir)
assert.Nil(t, err)

err = CaptchaWriteToFile(captcha, noPermissionDirPath, idKey, "png")
assert.NotNil(t, err)
//has no permission must failed
assert.Nil(t, err)
}

func TestSetCustomStore(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions engineAudio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package base64Captcha

import (
"io/ioutil"
"os"
"testing"
)

Expand Down Expand Up @@ -33,6 +34,7 @@ func BenchmarkAudioWriteTo(b *testing.B) {

func TestEngineAudioCreate(t *testing.T) {
ta, _ := ioutil.TempDir("", "audio")
defer os.RemoveAll(ta)
for i := 0; i < 10; i++ {
idKey := randomId()
au := EngineAudioCreate(idKey, configA)
Expand Down
3 changes: 2 additions & 1 deletion engineImageChar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package base64Captcha

import (
"io/ioutil"
"os"
"strings"
"testing"
)

func TestEngineCharCreate(t *testing.T) {
tc, _ := ioutil.TempDir("", "audio")

defer os.Remove(tc)
for i := 0; i < 16; i++ {
configC.Mode = i % 4
boooo := i%2 == 0
Expand Down
3 changes: 2 additions & 1 deletion engineImageDigit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package base64Captcha

import (
"io/ioutil"
"os"
"testing"
)

func TestEngineDigitsCreate(t *testing.T) {
td, _ := ioutil.TempDir("", "audio")

defer os.Remove(td)
for i := 0; i < 14; i++ {
idKey := randomId()
im := EngineDigitsCreate(idKey, configD)
Expand Down
2 changes: 1 addition & 1 deletion randomMath.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func randColor() color.RGBA {

red := r.Intn(255)
green := r.Intn(255)
blue := r.Intn(255)
var blue int
if (red + green) > 400 {
blue = 0
} else {
Expand Down
3 changes: 1 addition & 2 deletions store/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ func (s *memoryStore) collectOne(e *list.Element, specifyTime time.Time) *list.E
s.idByTime.Remove(e)
s.numStored--
return next
} else {
return nil
}
return nil
}
2 changes: 1 addition & 1 deletion store/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type redisStore struct {
expiration time.Duration
}

// NewRedisStoreByDetail returns a new redis store for captcha with the
// NewRedisStore newRedisStoreByDetail returns a new redis store for captcha with the
// given collection threshold and expiration time (duration). The returned
// store can registered with SetCustomStore to replace the default one.
func NewRedisStore(client *redis.Client, prefix string, expiration time.Duration) Store {
Expand Down
4 changes: 2 additions & 2 deletions store/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestRedisStore_Get(t *testing.T) {
s := NewRedisStore(c, "test:", 5*time.Minute)
c.Set("test:"+id, value, 5*time.Minute)
assert.Equal(t, value, s.Get(id, false))
assert.Equal(t, value, c.Get("test:" + id).Val())
assert.Equal(t, value, c.Get("test:"+id).Val())
}

func TestRedisStore_GetAndClear(t *testing.T) {
Expand All @@ -40,7 +40,7 @@ func TestRedisStore_GetAndClear(t *testing.T) {
s := NewRedisStore(c, "test:", 5*time.Minute)
c.Set("test:"+id, value, 5*time.Minute)
assert.Equal(t, value, s.Get(id, true))
assert.Equal(t, int64(0), c.Exists("test:" + id).Val())
assert.Equal(t, int64(0), c.Exists("test:"+id).Val())
}

func TestNewRedisStoreByClient(t *testing.T) {
Expand Down

0 comments on commit dcf3942

Please sign in to comment.