You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
log.Fatalf("Error while reading file : %v\n", err)
120
121
}
121
122
122
-
outputCassette:=cassette.New(path)
123
+
outputCassette:=cassetteV3.New(path)
124
+
transitioning:=false
125
+
126
+
report:=CompressReport{
127
+
SkippedInteraction: 0,
128
+
Path: path,
129
+
ErrorLogs: []string{},
130
+
Logs: []string{},
131
+
}
132
+
133
+
fori:=rangelen(inputCassette.Interactions) {
134
+
interaction:=inputCassette.Interactions[i]
135
+
responseBody:=interaction.Response.Body
136
+
requestMethod:=interaction.Request.Method
137
+
138
+
ifrequestMethod!="GET" {
139
+
transitioning=false
140
+
141
+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is not a GET request. Recording it\n", i, path))
142
+
outputCassette.AddInteraction(interaction)
143
+
144
+
continue
145
+
}
146
+
147
+
ifresponseBody=="" {
148
+
report.AddLog(fmt.Sprintf("Interaction %d in test %s got an empty response body. Recording it\n", i, path))
149
+
outputCassette.AddInteraction(interaction)
150
+
151
+
continue
152
+
}
153
+
154
+
varmmap[string]any
155
+
156
+
err:=json.Unmarshal([]byte(responseBody), &m)
157
+
iferr!=nil {
158
+
report.AddErrorLog(fmt.Sprintf("Interaction %d in test %s have an error with unmarshalling response body: %v. Recording it\n", i, path, err))
159
+
outputCassette.AddInteraction(interaction)
160
+
161
+
continue
162
+
}
163
+
164
+
ifm["status"] ==nil {
165
+
report.AddLog(fmt.Sprintf("Interaction %d in test %s does not contain a status field. Recording it\n", i, path))
166
+
outputCassette.AddInteraction(interaction)
167
+
168
+
continue
169
+
}
170
+
171
+
status:=m["status"].(string)
172
+
// We test if the state is transient
173
+
if_, ok:=transientStates[status]; ok {
174
+
iftransitioning {
175
+
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))
176
+
report.SkippedInteraction++
177
+
} else {
178
+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is in a transient state: %s, Recording it\n", i, path, status))
179
+
180
+
transitioning=true
181
+
182
+
outputCassette.AddInteraction(interaction)
183
+
}
184
+
} else {
185
+
iftransitioning {
186
+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is not in a transient state anymore: %s, Recording it\n", i, path, status))
187
+
outputCassette.AddInteraction(interaction)
188
+
189
+
transitioning=false
190
+
} else {
191
+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is not in a transient state: %s, Recording it\n", i, path, status))
192
+
outputCassette.AddInteraction(interaction)
193
+
}
194
+
}
195
+
}
196
+
197
+
err=outputCassette.Save()
198
+
iferr!=nil {
199
+
returnreport, fmt.Errorf("error while saving file: %w", err)
0 commit comments