@@ -6,20 +6,34 @@ import (
66 "time"
77)
88
9- type TestOptions struct {
10- Root string
11- RunFilter string
12- FormatName string
13- OutputPath string
14- Commit bool
15- NoRestore bool
16- ForceRestore bool
17- FailOnSkipped bool
18- Color bool
19- NoColor bool
20- FullDiff bool
21- NoDiff bool
22- }
9+ type (
10+ TestOptions struct {
11+ Root string
12+ RunFilter string
13+ FormatName string
14+ OutputPath string
15+ Commit bool
16+ NoRestore bool
17+ ForceRestore bool
18+ FailOnSkipped bool
19+ Color bool
20+ NoColor bool
21+ FullDiff bool
22+ NoDiff bool
23+ }
24+
25+ UpdateOptions struct {
26+ Root string
27+ RunFilter string
28+ Paths []string
29+ Commit bool
30+ NoRestore bool
31+ ForceRestore bool
32+ Pending bool
33+ Interactive bool
34+ DryRun bool
35+ }
36+ )
2337
2438/*
2539Init initializes a code repository for RegreSQL processing.
@@ -108,37 +122,38 @@ case and add a value for each parameter. `)
108122Update updates the expected files from the queries and their parameters.
109123Each query runs in its own transaction that rolls back (unless commit is true).
110124*/
111- func Update (root string , runFilter string , commit , noRestore , forceRestore bool ) {
112- config , err := ReadConfig (root )
125+ func Update (opts UpdateOptions ) {
126+ config , err := ReadConfig (opts . Root )
113127 ignorePatterns := []string {}
114128 if err == nil {
115129 ignorePatterns = config .Ignore
116130 }
117131
118- suite := Walk (root , ignorePatterns )
119- suite .SetRunFilter (runFilter )
132+ suite := Walk (opts .Root , ignorePatterns )
133+ suite .SetRunFilter (opts .RunFilter )
134+ suite .SetPathFilters (opts .Paths )
120135 config , err = suite .readConfig ()
121136 if err != nil {
122137 fmt .Print (err .Error ())
123138 os .Exit (3 )
124139 }
125140
126- autoRestore (config , root , noRestore , forceRestore )
141+ autoRestore (config , opts . Root , opts . NoRestore , opts . ForceRestore )
127142
128143 // Validate schema hasn't changed since last snapshot build
129- if err := ValidateSchemaHash (root ); err != nil {
144+ if err := ValidateSchemaHash (opts . Root ); err != nil {
130145 fmt .Printf ("Error: %s\n " , err )
131146 os .Exit (1 )
132147 }
133148
134149 // Validate migrations haven't changed since last snapshot build
135- if err := ValidateMigrationsHash (root ); err != nil {
150+ if err := ValidateMigrationsHash (opts . Root ); err != nil {
136151 fmt .Printf ("Error: %s\n " , err )
137152 os .Exit (1 )
138153 }
139154
140155 // Validate migration command hasn't changed since last snapshot build
141- if err := ValidateMigrationCommandHash (root ); err != nil {
156+ if err := ValidateMigrationCommandHash (opts . Root ); err != nil {
142157 fmt .Printf ("Error: %s\n " , err )
143158 os .Exit (1 )
144159 }
@@ -149,16 +164,26 @@ func Update(root string, runFilter string, commit, noRestore, forceRestore bool)
149164 }
150165
151166 // Validate server settings match snapshot (warn, strict, or ignore)
152- if err := validateServerSettings (config , root ); err != nil {
167+ if err := validateServerSettings (config , opts . Root ); err != nil {
153168 fmt .Printf ("Error: %s\n " , err )
154169 os .Exit (1 )
155170 }
156171
157- if err := suite .createExpectedResults (config .PgUri , commit ); err != nil {
172+ updateOpts := createExpectedOptions {
173+ Commit : opts .Commit ,
174+ Pending : opts .Pending ,
175+ Interactive : opts .Interactive ,
176+ DryRun : opts .DryRun ,
177+ }
178+ if err := suite .createExpectedResults (config .PgUri , updateOpts ); err != nil {
158179 fmt .Print (err .Error ())
159180 os .Exit (12 )
160181 }
161182
183+ if opts .DryRun {
184+ return // Don't print success message for dry-run
185+ }
186+
162187 fmt .Println ("" )
163188 fmt .Println (`Expected files have now been created.
164189You can run regression tests for your SQL queries with the command
0 commit comments