mirror of
https://github.com/jimeh/go-golden.git
synced 2026-02-19 11:16:47 +00:00
feat(options): add optional Options arguments to New() function (#14)
Enables simpler creation of custom *Golden instances, as you can just pass in the custom values to New(), rather than modifying fields after increating the Golden instance.
This commit is contained in:
58
options_test.go
Normal file
58
options_test.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package golden
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWithDirMode(t *testing.T) {
|
||||
customMode := os.FileMode(0o700)
|
||||
g := &Golden{}
|
||||
|
||||
opt := WithDirMode(customMode)
|
||||
opt(g)
|
||||
|
||||
assert.Equal(t, customMode, g.DirMode)
|
||||
}
|
||||
|
||||
func TestWithFileMode(t *testing.T) {
|
||||
customMode := os.FileMode(0o600)
|
||||
g := &Golden{}
|
||||
|
||||
opt := WithFileMode(customMode)
|
||||
opt(g)
|
||||
|
||||
assert.Equal(t, customMode, g.FileMode)
|
||||
}
|
||||
|
||||
func TestWithSuffix(t *testing.T) {
|
||||
customSuffix := ".custom"
|
||||
g := &Golden{}
|
||||
|
||||
opt := WithSuffix(customSuffix)
|
||||
opt(g)
|
||||
|
||||
assert.Equal(t, customSuffix, g.Suffix)
|
||||
}
|
||||
|
||||
func TestWithDirname(t *testing.T) {
|
||||
customDirname := "custom-testdata"
|
||||
g := &Golden{}
|
||||
|
||||
opt := WithDirname(customDirname)
|
||||
opt(g)
|
||||
|
||||
assert.Equal(t, customDirname, g.Dirname)
|
||||
}
|
||||
|
||||
func TestWithUpdateFunc(t *testing.T) {
|
||||
customUpdateFunc := func() bool { return true }
|
||||
g := &Golden{}
|
||||
|
||||
opt := WithUpdateFunc(customUpdateFunc)
|
||||
opt(g)
|
||||
|
||||
assertSameFunc(t, customUpdateFunc, g.UpdateFunc)
|
||||
}
|
||||
Reference in New Issue
Block a user