Files
threshold/internal/storage/options_test.go
T
Elim Tsiagbey 366128f079 Update Storage options to support rolling buffer (#798)
Add new storage options:
- `WithBuffer`:  WithBuffer sets the buffer size. The value must be a factorial of 4KiB.
- `WithMinimumBuffer`: WithMinimumBuffer sets the threshold to enforce when the buffer expands back to its original size.
2024-01-11 09:58:32 -05:00

83 lines
2.2 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package storage
import (
"testing"
"github.com/stretchr/testify/assert"
)
// Test_getOpts provides unit tests for GetOpts and all the options
func Test_getOpts(t *testing.T) {
t.Parallel()
t.Run("WithCloseSyncMode", func(t *testing.T) {
t.Parallel()
assert := assert.New(t)
testOpts := getDefaultOptions()
opts := GetOpts(WithCloseSyncMode(Asynchronous))
assert.Equal(testOpts, opts)
testOpts = getDefaultOptions()
opts = GetOpts(WithCloseSyncMode(Synchronous))
testOpts.WithCloseSyncMode = Synchronous
assert.Equal(opts, testOpts)
testOpts = getDefaultOptions()
opts = GetOpts(WithCloseSyncMode(NoSync))
testOpts.WithCloseSyncMode = NoSync
assert.Equal(opts, testOpts)
})
t.Run("WithFileAccessMode", func(t *testing.T) {
t.Parallel()
assert := assert.New(t)
testOpts := getDefaultOptions()
opts := GetOpts(WithFileAccessMode(ReadOnly))
assert.Equal(testOpts, opts)
testOpts = getDefaultOptions()
opts = GetOpts(WithFileAccessMode(WriteOnly))
testOpts.WithFileAccessMode = WriteOnly
assert.Equal(opts, testOpts)
testOpts = getDefaultOptions()
opts = GetOpts(WithFileAccessMode(ReadWrite))
testOpts.WithFileAccessMode = ReadWrite
assert.Equal(opts, testOpts)
})
t.Run("WithCreateFile", func(t *testing.T) {
t.Parallel()
assert := assert.New(t)
testOpts := getDefaultOptions()
opts := GetOpts()
testOpts.WithCreateFile = false
assert.Equal(testOpts, opts)
testOpts = getDefaultOptions()
opts = GetOpts(WithCreateFile())
testOpts.WithCreateFile = true
assert.Equal(opts, testOpts)
})
t.Run("WithBuffer", func(t *testing.T) {
testOpts := getDefaultOptions()
opts := GetOpts(WithBuffer(0))
assert.Equal(testOpts, opts)
testOpts = getDefaultOptions()
opts = GetOpts(WithBuffer(4096))
testOpts.WithBuffer = 4096
assert.Equal(opts, testOpts)
})
t.Run("WithMinimumBuffer", func(t *testing.T) {
testOpts := getDefaultOptions()
opts := GetOpts(WithMinimumBuffer(0))
assert.Equal(testOpts, opts)
testOpts = getDefaultOptions()
opts = GetOpts(WithMinimumBuffer(88))
testOpts.WithMinimumBuffer = 88
assert.Equal(opts, testOpts)
})
}