diff --git a/go/api/response_handlers.go b/go/api/response_handlers.go index 4ccb5d9a53..d2e2eea6a3 100644 --- a/go/api/response_handlers.go +++ b/go/api/response_handlers.go @@ -397,34 +397,41 @@ func handleStringSetResponse(response *C.struct_CommandResponse) (map[Result[str return slice, nil } -func describe(i interface{}) { - fmt.Printf("(%v, %T)\n", i, i) -} - func handleKeyWithMemberAndScoreResponse(response *C.struct_CommandResponse) (Result[KeyWithMemberAndScore], error) { defer C.free_command_response(response) - describe(response) - typeErr := checkResponseType(response, C.Array, false) + if response == nil || response.response_type == uint32(C.Null) { + return CreateNilKeyWithMemberAndScoreResult(), nil + } + + typeErr := checkResponseType(response, C.Array, true) if typeErr != nil { return CreateNilKeyWithMemberAndScoreResult(), typeErr } + if response.array_value_len != 3 { + return CreateNilKeyWithMemberAndScoreResult(), &RequestError{"Unexpected number of elements in response"} + } - return CreateNilKeyWithMemberAndScoreResult(), nil - // m := make(map[Result[string]]Result[float64], response.array_value_len) - // for _, v := range unsafe.Slice(response.array_value, response.array_value_len) { - // key, err := convertCharArrayToString(v.map_key, true) - // if err != nil { - // return nil, err - // } - // value, err := handleDoubleResponse(v.map_value) - // if err != nil { - // return nil, err - // } - // m[key] = value - // } - - // return m, nil + slice, err := parseArray(response) + if err != nil { + return CreateNilKeyWithMemberAndScoreResult(), err + } + + arr := slice.([]interface{}) + key, ok := arr[0].(string) + if !ok { + return CreateNilKeyWithMemberAndScoreResult(), &RequestError{"Unexpected type of key"} + } + member, ok := arr[1].(string) + if !ok { + return CreateNilKeyWithMemberAndScoreResult(), &RequestError{"Unexpected type of member"} + } + score := arr[2].(float64) + if !ok { + return CreateNilKeyWithMemberAndScoreResult(), &RequestError{"Unexpected type of score"} + } + kms := KeyWithMemberAndScore{key, member, score} + return CreateKeyWithMemberAndScoreResult(kms), nil } func handleScanResponse( diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index 02525e6f61..8c60a98f7f 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -3988,29 +3988,30 @@ func (suite *GlideTestSuite) TestBZPopMin() { assert.Equal(suite.T(), int64(1), zaddResult2.Value()) // Pop minimum element from key1 and key2 - bzpopminResult1, err := client.BZPopMin([]string{key1, key2}, float64(500*time.Millisecond)) + bzpopminResult1, err := client.BZPopMin([]string{key1, key2}, float64(.5)) assert.Nil(suite.T(), err) - assert.Equal(suite.T(), []interface{}{key1, "a", 1.0}, bzpopminResult1) + assert.Equal(suite.T(), api.KeyWithMemberAndScore{Key: key1, Member: "a", Score: 1.0}, bzpopminResult1.Value()) // Attempt to pop from non-existent key3 - bzpopminResult2, err := client.BZPopMin([]string{key3}, float64(1*time.Second)) + bzpopminResult2, err := client.BZPopMin([]string{key3}, float64(1)) assert.Nil(suite.T(), err) - assert.Nil(suite.T(), bzpopminResult2) + assert.True(suite.T(), bzpopminResult2.IsNil()) // Pop minimum element from key2 - bzpopminResult3, err := client.BZPopMin([]string{key3, key2}, float64(500*time.Millisecond)) + bzpopminResult3, err := client.BZPopMin([]string{key3, key2}, float64(.5)) assert.Nil(suite.T(), err) - assert.Equal(suite.T(), []interface{}{key2, "c", 2.0}, bzpopminResult3) + assert.Equal(suite.T(), api.KeyWithMemberAndScore{Key: key2, Member: "c", Score: 2.0}, bzpopminResult3.Value()) // Set key3 to a non-sorted set value setResult, err := client.Set(key3, "value") assert.Nil(suite.T(), err) - assert.Equal(suite.T(), "OK", setResult) + assert.Equal(suite.T(), "OK", setResult.Value()) - // // Attempt to pop from key3 which is not a sorted set - // _, err = client.BZPopMin([]string{key3}, float64(500*time.Millisecond)) - // assert.Error(suite.T(), err) - // assert.IsType(suite.T(), RequestException{}, err) + // Attempt to pop from key3 which is not a sorted set + _, err = client.BZPopMin([]string{key3}, float64(.5)) + if assert.Error(suite.T(), err) { + assert.IsType(suite.T(), &api.RequestError{}, err) + } }) }