Skip to content

Commit

Permalink
dumplib: Fix proto formatting instability in tests (google#2465)
Browse files Browse the repository at this point in the history
  • Loading branch information
pav-kv authored Apr 12, 2021
1 parent 76058cc commit 6e2798e
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions storage/tools/dump_tree/nochange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 20,9 @@ import (
"testing"

_ "github.com/google/trillian/crypto/keys/der/proto"
"github.com/google/trillian/storage/storagepb"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
)

// TestDBFormatNoChange ensures that the prefix, suffix, and protos stored in the database do not change.
Expand Down Expand Up @@ -73,15 76,22 @@ func TestDBFormatNoChange(t *testing.T) {
t.Fatalf("ReadFile(%v): %v", tc.file, err)
}

savedS := strings.Split(string(saved), "\n")
outS := strings.Split(out, "\n")
savedS := strings.Split(string(saved), "\n\n")
outS := strings.Split(out, "\n\n")
if got, want := len(outS), len(savedS); got != want {
t.Fatalf("%v dump_tree: got %v lines, want %v", tc.desc, got, want)
}
for i := range savedS {
if got, want := savedS[i], outS[i]; got != want {
t.Errorf("%v dump_tree line %3v %v, want %v", tc.desc, i, got, want)
var got, want storagepb.SubtreeProto
if err := prototext.Unmarshal([]byte(outS[i]), &got); err != nil {
t.Fatalf("Failed to unmarshal 'got': %v", err)
}
if err := prototext.Unmarshal([]byte(savedS[i]), &want); err != nil {
t.Fatalf("Failed to unmarshal 'want': %v", err)
}
if !proto.Equal(&got, &want) {
t.Errorf("%v dump_tree tile %d:\n%v\nwant:\n%v", tc.desc, i, outS[i], savedS[i])
}
}
if got, want := len(savedS), len(outS); got != want {
t.Errorf("%v dump_tree %v lines, want %v", tc.desc, got, want)
}
}
}

0 comments on commit 6e2798e

Please sign in to comment.