...

Source file src/github.com/letsencrypt/boulder/db/rollback_test.go

Documentation: github.com/letsencrypt/boulder/db

     1  package db
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	berrors "github.com/letsencrypt/boulder/errors"
     8  	"github.com/letsencrypt/boulder/test"
     9  )
    10  
    11  func TestRollback(t *testing.T) {
    12  	ctx := context.Background()
    13  	dbMap := testDbMap(t)
    14  
    15  	tx, _ := dbMap.BeginTx(ctx)
    16  	// Commit the transaction so that a subsequent rollback will always fail.
    17  	_ = tx.Commit()
    18  
    19  	innerErr := berrors.NotFoundError("Gone, gone, gone")
    20  	result := rollback(tx, innerErr)
    21  
    22  	// Since the tx.Rollback will fail we expect the result to be a wrapped error
    23  	test.AssertNotEquals(t, result, innerErr)
    24  	if rbErr, ok := result.(*RollbackError); ok {
    25  		test.AssertEquals(t, rbErr.Err, innerErr)
    26  		test.AssertNotNil(t, rbErr.RollbackErr, "RollbackErr was nil")
    27  	} else {
    28  		t.Fatalf("Result was not a RollbackError: %#v", result)
    29  	}
    30  
    31  	// Create a new transaction and don't commit it this time. The rollback should
    32  	// succeed.
    33  	tx, _ = dbMap.BeginTx(ctx)
    34  	result = rollback(tx, innerErr)
    35  
    36  	// We expect that the err is returned unwrapped.
    37  	test.AssertEquals(t, result, innerErr)
    38  }
    39  

View as plain text