1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
11 check "gopkg.in/check.v1"
14 var _ = check.Suite(&filterEncodingSuite{})
16 type filterEncodingSuite struct{}
18 func (s *filterEncodingSuite) TestMarshalNanoseconds(c *check.C) {
20 t0str := t0.Format(time.RFC3339Nano)
21 buf, err := json.Marshal([]Filter{
22 {Attr: "modified_at", Operator: "=", Operand: t0}})
23 c.Assert(err, check.IsNil)
24 c.Check(string(buf), check.Equals, `[["modified_at","=","`+t0str+`"]]`)
27 func (s *filterEncodingSuite) TestMarshalNil(c *check.C) {
28 buf, err := json.Marshal([]Filter{
29 {Attr: "modified_at", Operator: "=", Operand: nil}})
30 c.Assert(err, check.IsNil)
31 c.Check(string(buf), check.Equals, `[["modified_at","=",null]]`)
34 func (s *filterEncodingSuite) TestUnmarshalNil(c *check.C) {
35 buf := []byte(`["modified_at","=",null]`)
37 err := f.UnmarshalJSON(buf)
38 c.Assert(err, check.IsNil)
39 c.Check(f, check.DeepEquals, Filter{Attr: "modified_at", Operator: "=", Operand: nil})
42 func (s *filterEncodingSuite) TestMarshalBoolean(c *check.C) {
43 buf, err := json.Marshal([]Filter{
44 {Attr: "is_active", Operator: "=", Operand: true}})
45 c.Assert(err, check.IsNil)
46 c.Check(string(buf), check.Equals, `[["is_active","=",true]]`)
49 func (s *filterEncodingSuite) TestUnmarshalBoolean(c *check.C) {
50 buf := []byte(`["is_active","=",true]`)
52 err := f.UnmarshalJSON(buf)
53 c.Assert(err, check.IsNil)
54 c.Check(f, check.DeepEquals, Filter{Attr: "is_active", Operator: "=", Operand: true})
57 func (s *filterEncodingSuite) TestUnmarshalBooleanExpression(c *check.C) {
58 buf := []byte(`"(foo < bar)"`)
60 err := f.UnmarshalJSON(buf)
61 c.Assert(err, check.IsNil)
62 c.Check(f, check.DeepEquals, Filter{Attr: "(foo < bar)", Operator: "=", Operand: true})