diff options
author | Rasmus Dahlberg <rasmus@mullvad.net> | 2021-12-28 21:32:38 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus@mullvad.net> | 2021-12-28 21:32:38 +0100 |
commit | 601d2ee04840d24fe13e5ec54ae09f2a623f3d02 (patch) | |
tree | 2ee254223b4aa4b3c52cc0c056c5d2dc45c385cf /pkg/db/trillian_test.go | |
parent | 04ca3b71764c0a958338ddacb92c2f474c5f4e78 (diff) |
db: Fix error prone timestamp configurationv0.3.4
The timestamp for the latest tree head is now set based on the current
UNIX time. This means that there is no longer any reliance on Trillian
to move the timestamp forward every 5 minutes, just set -interval=300s.
Diffstat (limited to 'pkg/db/trillian_test.go')
-rw-r--r-- | pkg/db/trillian_test.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/pkg/db/trillian_test.go b/pkg/db/trillian_test.go index a33458f..955fc46 100644 --- a/pkg/db/trillian_test.go +++ b/pkg/db/trillian_test.go @@ -1,10 +1,12 @@ package db import ( + "bytes" "context" "fmt" "reflect" "testing" + "time" "git.sigsum.org/sigsum-lib-go/pkg/requests" "git.sigsum.org/sigsum-lib-go/pkg/types" @@ -185,8 +187,18 @@ func TestGetTreeHead(t *testing.T) { if err != nil { return } - if got, want := th, table.wantTh; !reflect.DeepEqual(got, want) { - t.Errorf("got tree head\n\t%v\nbut wanted\n\t%v\nin test %q", got, want, table.description) + + // we would need a clock that can be mocked to make a nicer test + now := uint64(time.Now().Unix()) + if got, wantLow, wantHigh := th.Timestamp, now-5, now+5; got < wantLow || got > wantHigh { + t.Errorf("got tree head with timestamp %d but wanted between [%d, %d] in test %q", + got, wantLow, wantHigh, table.description) + } + if got, want := th.TreeSize, table.wantTh.TreeSize; got != want { + t.Errorf("got tree head with tree size %d but wanted %d in test %q", got, want, table.description) + } + if got, want := th.RootHash[:], table.wantTh.RootHash[:]; !bytes.Equal(got, want) { + t.Errorf("got root hash %x but wanted %x in test %q", got, want, table.description) } }() } |