mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
client: test unmarshaling of failure responses
This commit is contained in:
parent
9378413283
commit
11a6cb68a6
@ -597,3 +597,28 @@ func TestUnmarshalSuccessfulResponse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalFailedKeysResponse(t *testing.T) {
|
||||||
|
body := []byte(`{"errorCode":100,"message":"Key not found","cause":"/foo","index":18}`)
|
||||||
|
|
||||||
|
wantErr := Error{
|
||||||
|
Code: 100,
|
||||||
|
Message: "Key not found",
|
||||||
|
Cause: "/foo",
|
||||||
|
Index: uint64(18),
|
||||||
|
}
|
||||||
|
|
||||||
|
gotErr := unmarshalFailedKeysResponse(body)
|
||||||
|
if !reflect.DeepEqual(wantErr, gotErr) {
|
||||||
|
t.Errorf("unexpected error: want=%#v got=%#v", wantErr, gotErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalFailedKeysResponseBadJSON(t *testing.T) {
|
||||||
|
err := unmarshalFailedKeysResponse([]byte(`{"er`))
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("got nil error")
|
||||||
|
} else if _, ok := err.(Error); ok {
|
||||||
|
t.Errorf("error is of incorrect type *Error: %#v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user