File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,4 +31,10 @@ var _ = Describe("Examples", func() {
3131 "e" : []string {"a" , "b" , "c" },
3232 }).To (goldga .Match ())
3333 })
34+
35+ It ("multiple gold files in the same test" , func () {
36+ Expect ("foo" ).To (goldga .Match (goldga .WithDescription ("first gold file" )))
37+ Expect ("bar" ).To (goldga .Match (goldga .WithDescription ("second gold file" )))
38+ Expect ("foobar" ).To (goldga .Match (goldga .WithDescription ("third gold file" )))
39+ })
3440})
Original file line number Diff line number Diff line change 1616 }
1717}
1818'''
19+ "Examples multiple gold files in the same test (first gold file)" = '''
20+ (string) (len=3) "foo"
21+ '''
22+ "Examples multiple gold files in the same test (second gold file)" = '''
23+ (string) (len=3) "bar"
24+ '''
25+ "Examples multiple gold files in the same test (third gold file)" = '''
26+ (string) (len=6) "foobar"
27+ '''
1928"Examples string" = '''
2029(string) (len=3) "abc"
2130'''
Original file line number Diff line number Diff line change @@ -11,13 +11,24 @@ import (
1111 "github.com/spf13/afero"
1212)
1313
14+ type Option func (* Matcher )
15+
16+ // WithDescription adds an optional description to the gold file, allowing multiple gold files per test
17+ func WithDescription (description string ) Option {
18+ return func (matcher * Matcher ) {
19+ if s , ok := matcher .Storage .(* SuiteStorage ); ok {
20+ s .Name = fmt .Sprintf ("%s (%s)" , s .Name , description )
21+ }
22+ }
23+ }
24+
1425func getUpdateFile () bool {
1526 update , _ := strconv .ParseBool (os .Getenv ("UPDATE_GOLDEN" ))
1627 return update
1728}
1829
19- func Match () * Matcher {
20- return & Matcher {
30+ func Match (options ... Option ) * Matcher {
31+ m := & Matcher {
2132 Serializer : DefaultSerializer ,
2233 Transformer : DefaultTransformer ,
2334 Storage : & SuiteStorage {
@@ -28,6 +39,10 @@ func Match() *Matcher {
2839 Differ : DefaultDiffer ,
2940 UpdateFile : getUpdateFile (),
3041 }
42+ for _ , option := range options {
43+ option (m )
44+ }
45+ return m
3146}
3247
3348var _ types.GomegaMatcher = (* Matcher )(nil )
Original file line number Diff line number Diff line change @@ -151,3 +151,13 @@ var _ = Describe("Matcher", func() {
151151 testError (HaveOccurred ())
152152 })
153153})
154+
155+ var _ = Describe ("Options" , func () {
156+ Describe ("WithDescription" , func () {
157+ It ("should append a description to the test name, allowing multiple gold files per test" , func () {
158+ Expect ("foo" ).To (Match (WithDescription ("First Gold File" )))
159+ Expect ("bar" ).To (Match (WithDescription ("Second Gold File" )))
160+ Expect ("foobar" ).To (Match (WithDescription ("Third Gold File" )))
161+ })
162+ })
163+ })
Original file line number Diff line number Diff line change 1+ # Generated by goldga. DO NOT EDIT.
2+ [snapshots]
3+ "Options WithDescription should append a description to the test name, allowing multiple gold files per test (First Gold File)" = '''
4+ (string) (len=3) "foo"
5+ '''
6+ "Options WithDescription should append a description to the test name, allowing multiple gold files per test (Second Gold File)" = '''
7+ (string) (len=3) "bar"
8+ '''
9+ "Options WithDescription should append a description to the test name, allowing multiple gold files per test (Third Gold File)" = '''
10+ (string) (len=6) "foobar"
11+ '''
You can’t perform that action at this time.
0 commit comments