test(client-go): strengthen WriteArrayElements assertions and add README example
This commit is contained in:
@@ -742,7 +742,7 @@ func TestWriteArrayElementsSendsWriteCommandWithSparseOneof(t *testing.T) {
|
||||
DataTypeFloat,
|
||||
10,
|
||||
map[uint32]*MxValue{3: FloatValue(1.5)},
|
||||
0,
|
||||
42,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteArrayElements() error = %v", err)
|
||||
@@ -752,7 +752,20 @@ func TestWriteArrayElementsSendsWriteCommandWithSparseOneof(t *testing.T) {
|
||||
if cmd.GetKind() != pb.MxCommandKind_MX_COMMAND_KIND_WRITE {
|
||||
t.Fatalf("command kind = %s, want WRITE", cmd.GetKind())
|
||||
}
|
||||
val := cmd.GetWrite().GetValue()
|
||||
w := cmd.GetWrite()
|
||||
if w.GetServerHandle() != 1 {
|
||||
t.Fatalf("server handle = %d, want 1", w.GetServerHandle())
|
||||
}
|
||||
if w.GetItemHandle() != 2 {
|
||||
t.Fatalf("item handle = %d, want 2", w.GetItemHandle())
|
||||
}
|
||||
if w.GetUserId() == 0 {
|
||||
t.Fatal("user id = 0, want non-zero")
|
||||
}
|
||||
if w.GetUserId() != 42 {
|
||||
t.Fatalf("user id = %d, want 42", w.GetUserId())
|
||||
}
|
||||
val := w.GetValue()
|
||||
sa, ok := val.Kind.(*pb.MxValue_SparseArrayValue)
|
||||
if !ok {
|
||||
t.Fatalf("value kind is %T, want *pb.MxValue_SparseArrayValue", val.Kind)
|
||||
@@ -763,4 +776,14 @@ func TestWriteArrayElementsSendsWriteCommandWithSparseOneof(t *testing.T) {
|
||||
if sa.SparseArrayValue.GetElementDataType() != DataTypeFloat {
|
||||
t.Errorf("ElementDataType = %v, want DataTypeFloat", sa.SparseArrayValue.GetElementDataType())
|
||||
}
|
||||
if len(sa.SparseArrayValue.GetElements()) != 1 {
|
||||
t.Fatalf("len(Elements) = %d, want 1", len(sa.SparseArrayValue.GetElements()))
|
||||
}
|
||||
elem := sa.SparseArrayValue.GetElements()[0]
|
||||
if elem.GetIndex() != 3 {
|
||||
t.Errorf("element index = %d, want 3", elem.GetIndex())
|
||||
}
|
||||
if elem.GetValue().GetFloatValue() != 1.5 {
|
||||
t.Errorf("element float value = %v, want 1.5", elem.GetValue().GetFloatValue())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user