github.com/hashicorp/vault/sdk@v0.13.0/physical/cache_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package physical
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/hashicorp/go-hclog"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestTransactionalCache_TransactionLimits(t *testing.T) {
    14  	tc := []struct {
    15  		name        string
    16  		be          Backend
    17  		wantEntries int
    18  		wantSize    int
    19  	}{
    20  		{
    21  			name: "non-transactionlimits backend",
    22  			be:   &TestTransactionalNonLimitBackend{},
    23  
    24  			// Should return zeros to let the implementor choose defaults.
    25  			wantEntries: 0,
    26  			wantSize:    0,
    27  		},
    28  		{
    29  			name: "transactionlimits backend",
    30  			be: &TestTransactionalLimitBackend{
    31  				MaxEntries: 123,
    32  				MaxSize:    345,
    33  			},
    34  
    35  			// Should return underlying limits
    36  			wantEntries: 123,
    37  			wantSize:    345,
    38  		},
    39  	}
    40  
    41  	for _, tt := range tc {
    42  		t.Run(tt.name, func(t *testing.T) {
    43  			logger := hclog.NewNullLogger()
    44  
    45  			be := NewTransactionalCache(tt.be, 1024, logger, nil)
    46  
    47  			// Call the TransactionLimits method
    48  			maxEntries, maxBytes := be.TransactionLimits()
    49  
    50  			require.Equal(t, tt.wantEntries, maxEntries)
    51  			require.Equal(t, tt.wantSize, maxBytes)
    52  		})
    53  	}
    54  }