Skip to content

Commit

Permalink
Make uninitializedBegin test accurately test its intention
Browse files Browse the repository at this point in the history
This was previously creating and initializing a tree, and then testing what happened if you created a transaction on a tree ID that definitely didn't exist. What it was trying to test was something different, which is the case where a tree had been created/defined, but was not initialized with an empty log root yet. The test now reflects that. This allows google#3201 to avoid a nil check for something that otherwise will be guaranteed to exist.
  • Loading branch information
mhutchinson committed Dec 11, 2023
1 parent 572b3dd commit 124fa8a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions integration/storagetest/logtests.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,22 @@ func (*logTests) TestSnapshot(ctx context.Context, t *testing.T, s storage.LogSt

func (*logTests) TestReadWriteTransaction(ctx context.Context, t *testing.T, s storage.LogStorage, as storage.AdminStorage) {
activeLog := mustCreateTree(ctx, t, as, storageto.LogTree)
mustSignAndStoreLogRoot(ctx, t, s, activeLog, &types.LogRootV1{RootHash: []byte{0}})

tests := []struct {
desc string
tree *trillian.Tree
doBefore func()
wantNeedsInit bool
wantErr bool
wantLogRoot []byte
}{
{
desc: "uninitializedBegin",
tree: logTree(-1),
doBefore: func() {},
wantNeedsInit: true,
},
{
desc: "activeLogBegin",
tree: activeLog,
desc: "activeLogBegin",
doBefore: func() { mustSignAndStoreLogRoot(ctx, t, s, activeLog, &types.LogRootV1{RootHash: []byte{0}}) },
wantLogRoot: func() []byte {
b, err := (&types.LogRootV1{RootHash: []byte{0}}).MarshalBinary()
if err != nil {
Expand All @@ -175,7 +174,8 @@ func (*logTests) TestReadWriteTransaction(ctx context.Context, t *testing.T, s s

for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
err := s.ReadWriteTransaction(ctx, test.tree, func(ctx context.Context, tx storage.LogTreeTX) error {
test.doBefore()
err := s.ReadWriteTransaction(ctx, activeLog, func(ctx context.Context, tx storage.LogTreeTX) error {
root, err := tx.LatestSignedLogRoot(ctx)
if err != nil && !(err == storage.ErrTreeNeedsInit && test.wantNeedsInit) {
t.Fatalf("%v: LatestSignedLogRoot() returned err = %v", test.desc, err)
Expand Down

0 comments on commit 124fa8a

Please sign in to comment.