@@ -65,7 +65,7 @@ func formatPackerOptionsPath(testFolder string) string {
65
65
// SaveEc2KeyPair serializes and saves an Ec2KeyPair into the given folder. This allows you to create an Ec2KeyPair during setup
66
66
// and to reuse that Ec2KeyPair later during validation and teardown.
67
67
func SaveEc2KeyPair (t testing.TestingT , testFolder string , keyPair * aws.Ec2Keypair ) {
68
- SaveTestData (t , formatEc2KeyPairPath (testFolder ), true , keyPair )
68
+ saveTestData (t , formatEc2KeyPairPath (testFolder ), true , keyPair , false )
69
69
}
70
70
71
71
// LoadEc2KeyPair loads and unserializes an Ec2KeyPair from the given folder. This allows you to reuse an Ec2KeyPair that was
@@ -193,6 +193,15 @@ func FormatTestDataPath(testFolder string, filename string) string {
193
193
// any contents that exist in the file found at `path` will be overwritten. This has the potential for causing duplicated resources
194
194
// and should be used with caution. If `overwrite` is `false`, the save will be skipped and a warning will be logged.
195
195
func SaveTestData (t testing.TestingT , path string , overwrite bool , value interface {}) {
196
+ saveTestData (t , path , overwrite , value , true )
197
+ }
198
+
199
+ // saveTestData serializes and saves a value used at test time to the given path. This allows you to create some sort of test data
200
+ // (e.g., TerraformOptions) during setup and to reuse this data later during validation and teardown. If `overwrite` is `true`,
201
+ // any contents that exist in the file found at `path` will be overwritten. This has the potential for causing duplicated resources
202
+ // and should be used with caution. If `overwrite` is `false`, the save will be skipped and a warning will be logged.
203
+ // If `loggedVal` is `true`, the value will be logged as JSON.
204
+ func saveTestData (t testing.TestingT , path string , overwrite bool , value interface {}, loggedVal bool ) {
196
205
logger .Default .Logf (t , "Storing test data in %s so it can be reused later" , path )
197
206
198
207
if IsTestDataPresent (t , path ) {
@@ -209,7 +218,9 @@ func SaveTestData(t testing.TestingT, path string, overwrite bool, value interfa
209
218
t .Fatalf ("Failed to convert value %s to JSON: %v" , path , err )
210
219
}
211
220
212
- logger .Default .Logf (t , "Marshalled JSON: %s" , string (bytes ))
221
+ if loggedVal {
222
+ logger .Default .Logf (t , "Marshalled JSON: %s" , string (bytes ))
223
+ }
213
224
214
225
parentDir := filepath .Dir (path )
215
226
if err := os .MkdirAll (parentDir , 0777 ); err != nil {
0 commit comments