2016-07-12 11 views
0

我是redigomock的新手,並且通過文檔和Google搜索,我找不到有效的示例。我錯過了一些明顯的東西,但我希望我的測試能夠正常工作。如何期待redigomock中的非字符串值

鑑於此代碼:

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 
} 

而且這個測試:

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) 
 

 
}

我收到一個錯誤:

redigo: unexpected type for Bool, got type bool

心中已經e嘗試了很多方法將價值強加到預期的結果中,但無濟於事。

任何幫助表示感謝,提前謝謝!

回答

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) 
 
}

相關問題