1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
14 func TestMarshalFiltersWithNanoseconds(t *testing.T) {
16 t0str := t0.Format(time.RFC3339Nano)
17 buf, err := json.Marshal([]Filter{
18 {Attr: "modified_at", Operator: "=", Operand: t0}})
22 if expect := []byte(`[["modified_at","=","` + t0str + `"]]`); 0 != bytes.Compare(buf, expect) {
23 t.Errorf("Encoded as %q, expected %q", buf, expect)
27 func TestMarshalFiltersWithNil(t *testing.T) {
28 buf, err := json.Marshal([]Filter{
29 {Attr: "modified_at", Operator: "=", Operand: nil}})
33 if expect := []byte(`[["modified_at","=",null]]`); 0 != bytes.Compare(buf, expect) {
34 t.Errorf("Encoded as %q, expected %q", buf, expect)
38 func TestUnmarshalFiltersWithNil(t *testing.T) {
39 buf := []byte(`["modified_at","=",null]`)
41 err := f.UnmarshalJSON(buf)
45 expect := Filter{Attr: "modified_at", Operator: "=", Operand: nil}
46 if f.Attr != expect.Attr || f.Operator != expect.Operator || f.Operand != expect.Operand {
47 t.Errorf("Decoded as %q, expected %q", f, expect)
51 func TestMarshalFiltersWithBoolean(t *testing.T) {
52 buf, err := json.Marshal([]Filter{
53 {Attr: "is_active", Operator: "=", Operand: true}})
57 if expect := []byte(`[["is_active","=",true]]`); 0 != bytes.Compare(buf, expect) {
58 t.Errorf("Encoded as %q, expected %q", buf, expect)
62 func TestUnmarshalFiltersWithBoolean(t *testing.T) {
63 buf := []byte(`["is_active","=",true]`)
65 err := f.UnmarshalJSON(buf)
69 expect := Filter{Attr: "is_active", Operator: "=", Operand: true}
70 if f.Attr != expect.Attr || f.Operator != expect.Operator || f.Operand != expect.Operand {
71 t.Errorf("Decoded as %q, expected %q", f, expect)