X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/44c95f99098fa6c6acbfa82d4b6cbc6015eb6e39..d8d6bca4b5db4851a29473f08dc600816c977a21:/sdk/go/arvados/resource_list_test.go diff --git a/sdk/go/arvados/resource_list_test.go b/sdk/go/arvados/resource_list_test.go index 5642599b4c..b36e82c918 100644 --- a/sdk/go/arvados/resource_list_test.go +++ b/sdk/go/arvados/resource_list_test.go @@ -23,3 +23,51 @@ func TestMarshalFiltersWithNanoseconds(t *testing.T) { t.Errorf("Encoded as %q, expected %q", buf, expect) } } + +func TestMarshalFiltersWithNil(t *testing.T) { + buf, err := json.Marshal([]Filter{ + {Attr: "modified_at", Operator: "=", Operand: nil}}) + if err != nil { + t.Fatal(err) + } + if expect := []byte(`[["modified_at","=",null]]`); 0 != bytes.Compare(buf, expect) { + t.Errorf("Encoded as %q, expected %q", buf, expect) + } +} + +func TestUnmarshalFiltersWithNil(t *testing.T) { + buf := []byte(`["modified_at","=",null]`) + f := &Filter{} + err := f.UnmarshalJSON(buf) + if err != nil { + t.Fatal(err) + } + expect := Filter{Attr: "modified_at", Operator: "=", Operand: nil} + if f.Attr != expect.Attr || f.Operator != expect.Operator || f.Operand != expect.Operand { + t.Errorf("Decoded as %q, expected %q", f, expect) + } +} + +func TestMarshalFiltersWithBoolean(t *testing.T) { + buf, err := json.Marshal([]Filter{ + {Attr: "is_active", Operator: "=", Operand: true}}) + if err != nil { + t.Fatal(err) + } + if expect := []byte(`[["is_active","=",true]]`); 0 != bytes.Compare(buf, expect) { + t.Errorf("Encoded as %q, expected %q", buf, expect) + } +} + +func TestUnmarshalFiltersWithBoolean(t *testing.T) { + buf := []byte(`["is_active","=",true]`) + f := &Filter{} + err := f.UnmarshalJSON(buf) + if err != nil { + t.Fatal(err) + } + expect := Filter{Attr: "is_active", Operator: "=", Operand: true} + if f.Attr != expect.Attr || f.Operator != expect.Operator || f.Operand != expect.Operand { + t.Errorf("Decoded as %q, expected %q", f, expect) + } +}