Merge branch '22174-remove-actions-column'
[arvados.git] / sdk / go / arvados / resource_list_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package arvados
6
7 import (
8         "encoding/json"
9         "time"
10
11         check "gopkg.in/check.v1"
12 )
13
14 var _ = check.Suite(&filterEncodingSuite{})
15
16 type filterEncodingSuite struct{}
17
18 func (s *filterEncodingSuite) TestMarshalNanoseconds(c *check.C) {
19         t0 := time.Now()
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+`"]]`)
25 }
26
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]]`)
32 }
33
34 func (s *filterEncodingSuite) TestUnmarshalNil(c *check.C) {
35         buf := []byte(`["modified_at","=",null]`)
36         var f Filter
37         err := f.UnmarshalJSON(buf)
38         c.Assert(err, check.IsNil)
39         c.Check(f, check.DeepEquals, Filter{Attr: "modified_at", Operator: "=", Operand: nil})
40 }
41
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]]`)
47 }
48
49 func (s *filterEncodingSuite) TestUnmarshalBoolean(c *check.C) {
50         buf := []byte(`["is_active","=",true]`)
51         var f Filter
52         err := f.UnmarshalJSON(buf)
53         c.Assert(err, check.IsNil)
54         c.Check(f, check.DeepEquals, Filter{Attr: "is_active", Operator: "=", Operand: true})
55 }
56
57 func (s *filterEncodingSuite) TestUnmarshalBooleanExpression(c *check.C) {
58         buf := []byte(`"(foo < bar)"`)
59         var f Filter
60         err := f.UnmarshalJSON(buf)
61         c.Assert(err, check.IsNil)
62         c.Check(f, check.DeepEquals, Filter{Attr: "(foo < bar)", Operator: "=", Operand: true})
63 }