From 42d126c965703b5340eae8aad5f82d6811cc0a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Borov=C4=8Danin?= Date: Mon, 9 Mar 2020 11:41:43 +0100 Subject: [PATCH] Fix base version check (#1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dušan Borovčanin --- senml.go | 3 +++ senml_test.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/senml.go b/senml.go index 6151429..576e3e0 100644 --- a/senml.go +++ b/senml.go @@ -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 } diff --git a/senml_test.go b/senml_test.go index da9b522..03695e9 100644 --- a/senml_test.go +++ b/senml_test.go @@ -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 @@ -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,