16263: Adds test exposing a bug on filter unmarshalling.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Tue, 24 Mar 2020 21:03:34 +0000 (18:03 -0300)
committerPeter Amstutz <peter.amstutz@curii.com>
Mon, 13 Apr 2020 15:25:53 +0000 (11:25 -0400)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

sdk/go/arvados/resource_list_test.go

index 4e09c5375db980c60171f9209714c81f55aef152..b36e82c918298fa624cb290b12889cb8da2734c0 100644 (file)
@@ -34,3 +34,40 @@ func TestMarshalFiltersWithNil(t *testing.T) {
                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)
+       }
+}