| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package rawdatastore | 5 package rawdatastore |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "encoding/json" | 8 "encoding/json" |
| 9 "fmt" | 9 "fmt" |
| 10 "testing" | 10 "testing" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 func TestBadKeyEncode(t *testing.T) { | 135 func TestBadKeyEncode(t *testing.T) { |
| 136 t.Parallel() | 136 t.Parallel() |
| 137 | 137 |
| 138 Convey("bad keys", t, func() { | 138 Convey("bad keys", t, func() { |
| 139 Convey("incomplete", func() { | 139 Convey("incomplete", func() { |
| 140 So(KeyIncomplete(mkKey("aid", "ns", "kind", 1)), ShouldB
eFalse) | 140 So(KeyIncomplete(mkKey("aid", "ns", "kind", 1)), ShouldB
eFalse) |
| 141 So(KeyIncomplete(mkKey("aid", "ns", "kind", 0)), ShouldB
eTrue) | 141 So(KeyIncomplete(mkKey("aid", "ns", "kind", 0)), ShouldB
eTrue) |
| 142 }) | 142 }) |
| 143 | 143 |
| 144 Convey("invalid", func() { | 144 Convey("invalid", func() { |
| 145 » » » So(KeyValid(mkKey("aid", "ns", "hat", "face", "__kind__"
, 1), "ns", true), ShouldBeTrue) | 145 » » » So(KeyValid(mkKey("aid", "ns", "hat", "face", "__kind__"
, 1), true, "aid", "ns"), ShouldBeTrue) |
| 146 » » » So(KeyValid(mkKey("aid", "ns", "hat", "face", "kind", 1)
, "wat", false), ShouldBeFalse) | |
| 147 | 146 |
| 148 bads := []Key{ | 147 bads := []Key{ |
| 149 nil, | 148 nil, |
| 150 mkKey("", "ns", "hat", "face"), | 149 mkKey("", "ns", "hat", "face"), |
| 151 mkKey("aid", "ns", "base", 1, "", "id"), | 150 mkKey("aid", "ns", "base", 1, "", "id"), |
| 152 mkKey("aid", "ns", "hat", "face", "__kind__", 1)
, | 151 mkKey("aid", "ns", "hat", "face", "__kind__", 1)
, |
| 153 mkKey("aid", "ns", "hat", 0, "kind", 1), | 152 mkKey("aid", "ns", "hat", 0, "kind", 1), |
| 154 dumbKey1{mkKey("aid", "badNS", "hat", 1)}, | 153 dumbKey1{mkKey("aid", "badNS", "hat", 1)}, |
| 155 dumbKey2{}, | 154 dumbKey2{}, |
| 156 } | 155 } |
| 157 for _, k := range bads { | 156 for _, k := range bads { |
| 158 s := "<nil>" | 157 s := "<nil>" |
| 159 if k != nil { | 158 if k != nil { |
| 160 s = k.String() | 159 s = k.String() |
| 161 } | 160 } |
| 162 Convey(s, func() { | 161 Convey(s, func() { |
| 163 » » » » » So(KeyValid(k, "ns", false), ShouldBeFal
se) | 162 » » » » » So(KeyValid(k, false, "aid", "ns"), Shou
ldBeFalse) |
| 164 }) | 163 }) |
| 165 } | 164 } |
| 166 }) | 165 }) |
| 167 }) | 166 }) |
| 168 } | 167 } |
| 169 | 168 |
| 170 type keyWrap struct{ Key } | 169 type keyWrap struct{ Key } |
| 171 | 170 |
| 172 func (k keyWrap) Parent() Key { | 171 func (k keyWrap) Parent() Key { |
| 173 if k.Key.Parent() != nil { | 172 if k.Key.Parent() != nil { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 NewKey("aid", "ns", "parent", "", 1, nil), | 234 NewKey("aid", "ns", "parent", "", 1, nil), |
| 236 )} | 235 )} |
| 237 d, err := json.Marshal(t) | 236 d, err := json.Marshal(t) |
| 238 So(err, ShouldBeNil) | 237 So(err, ShouldBeNil) |
| 239 t2 := &TestStruct{} | 238 t2 := &TestStruct{} |
| 240 err = json.Unmarshal(d, t2) | 239 err = json.Unmarshal(d, t2) |
| 241 So(err, ShouldBeNil) | 240 So(err, ShouldBeNil) |
| 242 So(t, ShouldResemble, t2) | 241 So(t, ShouldResemble, t2) |
| 243 }) | 242 }) |
| 244 } | 243 } |
| OLD | NEW |