An assert created in the parent was being used in subtests, which will attribute test failures incorrectly. Also run tests in parallel.
63 lines
1.6 KiB
Go
63 lines
1.6 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)
|
|
})
|
|
}
|