aboutsummaryrefslogtreecommitdiff
path: root/crypto_test.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-18 17:51:05 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-18 17:51:05 +0100
commit55a0a1c9c2a6df4f05d539f0fc67a8c7052a338f (patch)
tree7a3608849a876338d2c4ed445bd0cda7182654ef /crypto_test.go
parent86573a8daaa9c0972c088e8b2ddec6fdb95d86d2 (diff)
fixed unexpected reflect behavior
After tls.Unmarshal() an empty slice is not assigned the nil value, but rather a slice of zero length. It is in contrast to NewTreeHeadV1(), which assigns a nil value. Therefore, reflect.DeepEqual() considers them to be different. Fixed by assigning an empty tree head extension as `make([]byte, 0)`, and not looking for nil values but rather zero-length values with len(). Further read: "Note that a non-nil empty slice and a nil slice [...] are not deeply equal." (https://golang.org/pkg/reflect/#DeepEqual).
Diffstat (limited to 'crypto_test.go')
-rw-r--r--crypto_test.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/crypto_test.go b/crypto_test.go
index cfbb0a8..75e530e 100644
--- a/crypto_test.go
+++ b/crypto_test.go
@@ -118,8 +118,8 @@ func TestGenV1Sth(t *testing.T) {
if got, want := sth.TreeHead.RootHash.Data, th.RootHash.Data; !bytes.Equal(got, want) {
t.Errorf("got root hash %X, wanted %X in test %q", got, want, table.description)
}
- if sth.TreeHead.Extension != nil {
- t.Errorf("got extensions %X, wanted nil in test %q", sth.TreeHead.Extension, table.description)
+ if len(sth.TreeHead.Extension) != 0 {
+ t.Errorf("got extensions %X, wanted none in test %q", sth.TreeHead.Extension, table.description)
}
}
}