Skip to content

Commit

Permalink
add some ifvalue tests and error checks
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Davis <[email protected]>
  • Loading branch information
duglin committed Jan 10, 2025
1 parent fc03628 commit ff16788
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ TODOs:
- multi-delete must ignore all attributes except id and epoch
- fix init.sql, it's too slow due to latest xref stuff in commit 9c583e7
- add support for inline=endpoints.*
- ban the use of ^ in ifvalue VALUES for now
- support ETag/If-Match
- update epoch/modifiedat of parent when nested entity is added/removed
- ?nested isn't needed to update `model` or `meta` attributes
Expand Down
5 changes: 5 additions & 0 deletions registry/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,11 @@ func (attrs Attributes) Verify(ld *LevelData) error {
return fmt.Errorf("%q has an empty ifvalues key", ld.Path.UI())
}

if valStr[0] == '^' {
return fmt.Errorf("%q has an ifvalues key that starts "+
"with \"^\"", ld.Path.UI())
}

nextLD := &LevelData{
ld.Model,
ld.AttrNames,
Expand Down
18 changes: 18 additions & 0 deletions tests/http1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4919,6 +4919,24 @@ func TestHTTPIfValue(t *testing.T) {
})
xCheckErr(t, err, "")

_, err = reg.Model.AddAttribute(&registry.Attribute{
Name: "badone",
Type: registry.INTEGER,
IfValues: registry.IfValues{
"": &registry.IfValue{},
},
})
xCheckErr(t, err, "\"model\" has an empty ifvalues key")

_, err = reg.Model.AddAttribute(&registry.Attribute{
Name: "badone",
Type: registry.INTEGER,
IfValues: registry.IfValues{
"^6": &registry.IfValue{},
},
})
xCheckErr(t, err, "\"model\" has an ifvalues key that starts with \"^\"")

xCheckHTTP(t, reg, &HTTPTest{
Name: "PUT reg - ifvalue - 1",
URL: "",
Expand Down

0 comments on commit ff16788

Please sign in to comment.