Skip to content

Commit

Permalink
Define a Wrapper function type. This should help to guarantee that wr…
Browse files Browse the repository at this point in the history
…apper functions are properly defined
  • Loading branch information
franiglesias committed Jan 26, 2024
1 parent 093fd83 commit 5fe327b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 6 additions & 9 deletions golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import (
"sync"
)

type Vals func(v ...[]any) [][]any
type Wrapper func(args ...any) any

func Combine(v ...[]any) [][]any {
return v
}

/*
Golden is the type that manage snapshotting and test evaluation
*/
Expand Down Expand Up @@ -104,7 +97,7 @@ The parameters received by the wrapper function are the result of combining all
the possible values for each parameter that you would pass to the SUT. This will
create a lot of tests (tenths or hundredths).
*/
func (g *Golden) Master(t Failable, f func(args ...any) any, values [][]any, options ...Option) {
func (g *Golden) Master(t Failable, f combinatory.Wrapper, values [][]any, options ...Option) {
g.global.ext = ".snap.json"
subject := combinatory.Master(f, values...)
g.Verify(t, subject, options...)
Expand Down Expand Up @@ -203,7 +196,7 @@ TL;DR Generates and executes SUT with all possible combinations of values
This is a tiny wrapper around the Golden.Master method.
*/
func Master(t Failable, f func(args ...any) any, values [][]any, options ...Option) {
func Master(t Failable, f combinatory.Wrapper, values [][]any, options ...Option) {
G.Master(t, f, values, options...)
}

Expand Down Expand Up @@ -275,3 +268,7 @@ between expected snapshot and subject
type DiffReporter interface {
Differences(want, got string) string
}

func Combine(v ...[]any) [][]any {
return v
}
2 changes: 2 additions & 0 deletions internal/combinatory/golden_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ func joinSliceAsString(a []any) string {
}
return strings.Join(result, ", ")
}

type Wrapper func(args ...any) any

0 comments on commit 5fe327b

Please sign in to comment.