2023-03-28 09:39:28 -07:00
|
|
|
// 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) {
|
2023-11-01 21:00:53 -07:00
|
|
|
t.Parallel()
|
|
|
|
|
assert := assert.New(t)
|
2023-03-28 09:39:28 -07:00
|
|
|
testOpts := getDefaultOptions()
|
2023-04-03 20:38:38 +00:00
|
|
|
opts := GetOpts(WithCloseSyncMode(Asynchronous))
|
2023-03-28 09:39:28 -07:00
|
|
|
assert.Equal(testOpts, opts)
|
|
|
|
|
|
|
|
|
|
testOpts = getDefaultOptions()
|
2023-04-03 20:38:38 +00:00
|
|
|
opts = GetOpts(WithCloseSyncMode(Synchronous))
|
|
|
|
|
testOpts.WithCloseSyncMode = Synchronous
|
2023-03-28 09:39:28 -07:00
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
|
|
|
|
|
testOpts = getDefaultOptions()
|
2023-04-03 20:38:38 +00:00
|
|
|
opts = GetOpts(WithCloseSyncMode(NoSync))
|
|
|
|
|
testOpts.WithCloseSyncMode = NoSync
|
2023-03-28 09:39:28 -07:00
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
|
|
|
|
t.Run("WithFileAccessMode", func(t *testing.T) {
|
2023-11-01 21:00:53 -07:00
|
|
|
t.Parallel()
|
|
|
|
|
assert := assert.New(t)
|
2023-03-28 09:39:28 -07:00
|
|
|
testOpts := getDefaultOptions()
|
2023-04-03 20:38:38 +00:00
|
|
|
opts := GetOpts(WithFileAccessMode(ReadOnly))
|
2023-03-28 09:39:28 -07:00
|
|
|
assert.Equal(testOpts, opts)
|
|
|
|
|
|
|
|
|
|
testOpts = getDefaultOptions()
|
2023-04-03 20:38:38 +00:00
|
|
|
opts = GetOpts(WithFileAccessMode(WriteOnly))
|
|
|
|
|
testOpts.WithFileAccessMode = WriteOnly
|
2023-03-28 09:39:28 -07:00
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
|
|
|
|
|
testOpts = getDefaultOptions()
|
2023-04-03 20:38:38 +00:00
|
|
|
opts = GetOpts(WithFileAccessMode(ReadWrite))
|
|
|
|
|
testOpts.WithFileAccessMode = ReadWrite
|
2023-03-28 09:39:28 -07:00
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
|
|
|
|
t.Run("WithCreateFile", func(t *testing.T) {
|
2023-11-01 21:00:53 -07:00
|
|
|
t.Parallel()
|
|
|
|
|
assert := assert.New(t)
|
2023-03-28 09:39:28 -07:00
|
|
|
testOpts := getDefaultOptions()
|
2023-04-03 20:38:38 +00:00
|
|
|
opts := GetOpts()
|
|
|
|
|
testOpts.WithCreateFile = false
|
2023-03-28 09:39:28 -07:00
|
|
|
assert.Equal(testOpts, opts)
|
|
|
|
|
|
|
|
|
|
testOpts = getDefaultOptions()
|
2023-04-03 20:38:38 +00:00
|
|
|
opts = GetOpts(WithCreateFile())
|
|
|
|
|
testOpts.WithCreateFile = true
|
2023-03-28 09:39:28 -07:00
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
2023-11-28 10:17:17 -05:00
|
|
|
t.Run("WithBuffer", func(t *testing.T) {
|
2024-01-08 19:23:07 -05:00
|
|
|
t.Parallel()
|
|
|
|
|
assert := assert.New(t)
|
2023-11-28 10:17:17 -05:00
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
opts := GetOpts(WithBuffer(0))
|
|
|
|
|
assert.Equal(testOpts, opts)
|
|
|
|
|
|
|
|
|
|
testOpts = getDefaultOptions()
|
|
|
|
|
opts = GetOpts(WithBuffer(4096))
|
|
|
|
|
testOpts.WithBuffer = 4096
|
|
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
2023-12-15 15:26:35 -08:00
|
|
|
|
|
|
|
|
t.Run("WithMinimumAvailableDiskSpace", func(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
opts := GetOpts()
|
|
|
|
|
assert.Equal(testOpts, opts)
|
|
|
|
|
|
|
|
|
|
testOpts = getDefaultOptions()
|
|
|
|
|
opts = GetOpts(WithMinimumAvailableDiskSpace(4096))
|
|
|
|
|
testOpts.WithMinimumAvailableDiskSpace = 4096
|
|
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
2023-03-28 09:39:28 -07:00
|
|
|
}
|