Skip to content

Commit 0e46054

Browse files
committed
refactor: update test struct to manage cases causing errors
1 parent e3f9841 commit 0e46054

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

internal/requests/requests_test.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,10 +1045,11 @@ func TestPrintRequestDebug(t *testing.T) {
10451045
expectedOutputIncomplete := "Warning: failed to dump request: http: nil Request.Header\n"
10461046

10471047
tests := []struct {
1048-
desc string
1049-
verbose bool
1050-
request *http.Request
1051-
output string
1048+
desc string
1049+
verbose bool
1050+
request *http.Request
1051+
output string
1052+
expectErr bool
10521053
}{
10531054
{
10541055
desc: "verboseTrue",
@@ -1064,16 +1065,18 @@ func TestPrintRequestDebug(t *testing.T) {
10641065
output: emptyString,
10651066
},
10661067
{
1067-
desc: "nilRequestError",
1068-
verbose: true,
1069-
request: requestTestNilPointer,
1070-
output: emptyString,
1068+
desc: "nilRequestError",
1069+
verbose: true,
1070+
request: requestTestNilPointer,
1071+
output: emptyString,
1072+
expectErr: true,
10711073
},
10721074
{
1073-
desc: "incompleteRequestError",
1074-
verbose: true,
1075-
request: &requestTestIncomplete,
1076-
output: expectedOutputIncomplete,
1075+
desc: "incompleteRequestError",
1076+
verbose: true,
1077+
request: &requestTestIncomplete,
1078+
output: expectedOutputIncomplete,
1079+
expectErr: true,
10771080
},
10781081
}
10791082

@@ -1085,8 +1088,11 @@ func TestPrintRequestDebug(t *testing.T) {
10851088
r := RequestConfig{RequestDebug: tt.verbose}
10861089

10871090
err := r.PrintRequestDebug(&buffer, tt.request)
1088-
if err != nil {
1089-
require.Error(t, err, "PrintRequestDebug error")
1091+
1092+
if tt.expectErr {
1093+
require.Error(t, err, "PrintRequestDebug should return an error")
1094+
} else {
1095+
require.NoError(t, err, "PrintRequestDebug should not return an error")
10901096
}
10911097

10921098
got := buffer.String()

0 commit comments

Comments
 (0)