diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-02-23 11:59:46 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-02-23 11:59:46 +0100 |
commit | b4dd74a3f36ca46b7bcda69e8d95949babfeb76d (patch) | |
tree | 6f3cbe32be4e675ba385e2575e28cf7a0f4dca00 /types/stitem_test.go | |
parent | 1505c6db8e0e66d88a645ac5cc36647a6f8b2f43 (diff) |
renamed and reordered to improve readability
Diffstat (limited to 'types/stitem_test.go')
-rw-r--r-- | types/stitem_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/types/stitem_test.go b/types/stitem_test.go new file mode 100644 index 0000000..c6e413a --- /dev/null +++ b/types/stitem_test.go @@ -0,0 +1,40 @@ +package types + +import ( + "strings" + "testing" +) + +// TestStItemString checks that the String() function prints the right format, +// and that the body is printed without a nil-pointer panic. +func TestStItemString(t *testing.T) { + wantPrefix := map[StFormat]string{ + StFormatReserved: "Format(reserved)", + StFormatSignedTreeHeadV1: "Format(signed_tree_head_v1): &{TreeHead", + StFormatCosignedTreeHeadV1: "Format(cosigned_tree_head_v1): &{SignedTreeHead", + StFormatConsistencyProofV1: "Format(consistency_proof_v1): &{LogId", + StFormatInclusionProofV1: "Format(inclusion_proof_v1): &{LogId", + StFormatSignedChecksumV1: "Format(signed_checksum_v1): &{Data", + StFormat(1<<16 - 1): "unknown StItem: unknown StFormat: 65535", + } + tests := append(test_cases_stitem(t), testCaseSerialize{ + description: "valid: unknown StItem", + item: StItem{ + Format: StFormat(1<<16 - 1), + }, + }) + for _, table := range tests { + item, ok := table.item.(StItem) + if !ok { + t.Fatalf("must cast to StItem in test %q", table.description) + } + + prefix, ok := wantPrefix[item.Format] + if !ok { + t.Fatalf("must have prefix for StFormat %v in test %q", item.Format, table.description) + } + if got, want := item.String(), prefix; !strings.HasPrefix(got, want) { + t.Errorf("got %q but wanted prefix %q in test %q", got, want, table.description) + } + } +} |