Skip to content

Commit 400a80a

Browse files
committed
golangci-lint fix
1 parent 99b2336 commit 400a80a

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

internal/acctest/compress_cassettes_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ func TestAccCassettes_Compressed(t *testing.T) {
1717
for path := range paths {
1818
g.Go(func() error {
1919
report, errCompression := acctest.CompressCassette(path)
20-
require.Nil(t, errCompression)
20+
require.NoError(t, errCompression)
2121
require.Zero(t, report.SkippedInteraction, "Issue with cassette: %s", report.Path)
22+
2223
return nil
2324
})
2425
}

internal/acctest/vcr_compress.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,18 @@ var transientStates = map[string]bool{
8282
}
8383

8484
type CompressReport struct {
85-
SkippedInteraction int
8685
Path string
8786
Logs []string
8887
ErrorLogs []string
88+
SkippedInteraction int
89+
}
90+
91+
func (report *CompressReport) AddLog(log string) {
92+
report.Logs = append(report.Logs, log)
93+
}
94+
95+
func (report *CompressReport) AddErrorLog(log string) {
96+
report.ErrorLogs = append(report.ErrorLogs, log)
8997
}
9098

9199
func CompressCassette(path string) (CompressReport, error) {
@@ -112,14 +120,14 @@ func CompressCassette(path string) (CompressReport, error) {
112120
if requestMethod != "GET" {
113121
transitioning = false
114122

115-
report.Logs = append(report.Logs, fmt.Sprintf("Interaction %d in test %s is not a GET request. Recording it\n", i, path))
123+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is not a GET request. Recording it\n", i, path))
116124
outputCassette.AddInteraction(interaction)
117125

118126
continue
119127
}
120128

121129
if responseBody == "" {
122-
report.Logs = append(report.Logs, fmt.Sprintf("Interaction %d in test %s got an empty response body. Recording it\n", i, path))
130+
report.AddLog(fmt.Sprintf("Interaction %d in test %s got an empty response body. Recording it\n", i, path))
123131
outputCassette.AddInteraction(interaction)
124132

125133
continue
@@ -129,14 +137,14 @@ func CompressCassette(path string) (CompressReport, error) {
129137

130138
err := json.Unmarshal([]byte(responseBody), &m)
131139
if err != nil {
132-
report.ErrorLogs = append(report.ErrorLogs, fmt.Sprintf("Interaction %d in test %s have an error with unmarshalling response body: %v. Recording it\n", i, path, err))
140+
report.AddErrorLog(fmt.Sprintf("Interaction %d in test %s have an error with unmarshalling response body: %v. Recording it\n", i, path, err))
133141
outputCassette.AddInteraction(interaction)
134142

135143
continue
136144
}
137145

138146
if m["status"] == nil {
139-
report.Logs = append(report.Logs, fmt.Sprintf("Interaction %d in test %s does not contain a status field. Recording it\n", i, path))
147+
report.AddLog(fmt.Sprintf("Interaction %d in test %s does not contain a status field. Recording it\n", i, path))
140148
outputCassette.AddInteraction(interaction)
141149

142150
continue
@@ -146,30 +154,31 @@ func CompressCassette(path string) (CompressReport, error) {
146154
// We test if the state is transient
147155
if _, ok := transientStates[status]; ok {
148156
if transitioning {
149-
report.Logs = append(report.Logs, fmt.Sprintf("Interaction %d in test %s is in a transient state while we are already in transitient state. No need to record it: %s\n", i, path, status))
157+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is in a transient state while we are already in transitient state. No need to record it: %s\n", i, path, status))
150158
report.SkippedInteraction++
151159
} else {
152-
report.Logs = append(report.Logs, fmt.Sprintf("Interaction %d in test %s is in a transient state: %s, Recording it\n", i, path, status))
160+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is in a transient state: %s, Recording it\n", i, path, status))
153161

154162
transitioning = true
155163

156164
outputCassette.AddInteraction(interaction)
157165
}
158166
} else {
159167
if transitioning {
160-
report.Logs = append(report.Logs, fmt.Sprintf("Interaction %d in test %s is not in a transient state anymore: %s, Recording it\n", i, path, status))
168+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is not in a transient state anymore: %s, Recording it\n", i, path, status))
161169
outputCassette.AddInteraction(interaction)
170+
162171
transitioning = false
163172
} else {
164-
report.Logs = append(report.Logs, fmt.Sprintf("Interaction %d in test %s is not in a transient state: %s, Recording it\n", i, path, status))
173+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is not in a transient state: %s, Recording it\n", i, path, status))
165174
outputCassette.AddInteraction(interaction)
166175
}
167176
}
168177
}
169178

170179
err = outputCassette.Save()
171180
if err != nil {
172-
return report, fmt.Errorf("error while saving file: %v", err)
181+
return report, fmt.Errorf("error while saving file: %w", err)
173182
}
174183

175184
return report, nil

0 commit comments

Comments
 (0)