rafaeljusto/redigomock

Documentation Limitation

Closed this issue · 3 comments

func TestCheckPasswordFailures_MoreThan5(t *testing.T) {

conn := redigomock.NewConn()

conn.Command("EXISTS", "test@xxx.com_pwf").Expect(true)
conn.Command("GET", "test@xxx.com_pwf").Expect(6)

actual := checkPasswordFailures(conn, mockUser)

assert.False(t, actual)

}

[error] error in checkPasswordFailures: redigo: unexpected type for Bool, got type bool

There is some documentation on mapping to a struct, but nothing at all about basic values such as strings, ints, bools. How do I respond to the command with a Bool or an int?

Here's the function being tested:
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

}

conn.Command("EXISTS", "test@xxx.com_pwf").Expect(1)
Yields error:error in checkPasswordFailures: redigo: unexpected type for Bool, got type int

func TestCheckPasswordFailures_LessThan5(t *testing.T) {

    conn := redigomock.NewConn()

    conn.Command("EXISTS", "test@xxx.com_pwf").Expect([]byte("true"))
    conn.Command("GET", "test@xxx.com_pwf").Expect(int64(1))

    actual := checkPasswordFailures(conn, mockUser)

    assert.True(t, actual)

}

Fixed it