This makes it possible to have external packages implement the storage.FS, storage.Container, and storage.File interfaces and correctly inspect the various options.
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
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()
|
|
assert := assert.New(t)
|
|
t.Run("WithCloseSyncMode", func(t *testing.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) {
|
|
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) {
|
|
testOpts := getDefaultOptions()
|
|
opts := GetOpts()
|
|
testOpts.WithCreateFile = false
|
|
assert.Equal(testOpts, opts)
|
|
|
|
testOpts = getDefaultOptions()
|
|
opts = GetOpts(WithCreateFile())
|
|
testOpts.WithCreateFile = true
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
}
|