Skip to content

Commit

Permalink
Fix base version check (absmach#1)
Browse files Browse the repository at this point in the history
Signed-off-by: Dušan Borovčanin <[email protected]>
  • Loading branch information
dborovcanin authored Mar 9, 2020
1 parent 7cb7855 commit 42d126c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions senml.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ func Validate(p Pack) error {
if bver == 0 && r.BaseVersion != 0 {
bver = r.BaseVersion
}
if bver != 0 && r.BaseVersion == 0 {
r.BaseVersion = bver
}
if r.BaseVersion != bver {
return ErrVersionChange
}
Expand Down
8 changes: 8 additions & 0 deletions senml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ func TestValidate(t *testing.T) {
noValue.Records[0].BaseSum = 0
noValue.Records[0].Sum = nil

validVersion := pack()
validVersion.Records[1].BaseVersion = 0

multiVersion := pack()
multiVersion.Records[1].BaseVersion = 3

Expand Down Expand Up @@ -235,6 +238,11 @@ func TestValidate(t *testing.T) {
p: noValue,
err: senml.ErrNoValues,
},
{
desc: "validate version",
p: validVersion,
err: nil,
},
{
desc: "validate multiple versions",
p: multiVersion,
Expand Down

0 comments on commit 42d126c

Please sign in to comment.