2016-07-12 4 views
0

私はredigomockを初めて使いました。ドキュメントやグーグルでは、わかりやすい例が見つかりません。私は何かを明らかにしていませんが、私のテストがうまくいくようにしたいと思います。redigomockで文字列以外の値を期待する方法

redigo: unexpected type for Bool, got type bool

I'v:私はエラーが表示さ

func TestCheckPasswordFailures_LessThan5(t *testing.T) { 
 

 
\t conn := redigomock.NewConn() 
 

 
\t conn.Command("EXISTS", "[email protected]_pwf").Expect(true) 
 
\t conn.Command("GET", "[email protected]_pwf").Expect(3) 
 

 
\t actual := checkPasswordFailures(conn, mockUser) 
 

 
\t assert.True(t, actual) 
 

 
}

var checkPasswordFailures = func(client redis.Conn, u *User) bool { 
    var userkey = getPasswordFailKey(u) 
    var existing, err = redis.Bool(client.Do("EXISTS", userkey)) 

    fmt.Printf("%s - existing = %v\n", userkey, existing) 

    if err != nil { 
     Log.Errorf("error in checkPasswordFailures: %s", err.Error()) 
    } 
    if existing == true { 
     fmt.Println("Existing true") 
     reply, err := redis.Int(client.Do("GET", userkey)) 

     Log.Debug("Attempt Count: %d", reply) 

     if err != nil { 
      Log.Errorf("error in checkPasswordFailures: %s", err.Error()) 
     } 
     return reply < 5 
    } 
    fmt.Println("Using default") 
    return true 
} 

そして、このテスト:

は、このコードを考えます値を期待された結果に強制する多くのアプローチを試みたが、役に立たなかった。

何かお手数ですが、よろしくお願いいたします。

答えて

1

func TestCheckPasswordFailures_LessThan5(t *testing.T) { 
 

 
conn := redigomock.NewConn() 
 

 
conn.Command("EXISTS", "[email protected]_pwf").Expect([]byte("true")) 
 
conn.Command("GET", "[email protected]_pwf").Expect(int64(1)) 
 

 
actual := checkPasswordFailures(conn, mockUser) 
 

 
assert.True(t, actual) 
 
}

関連する問題