Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion execution/engine/execution_engine_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,54 @@ func createTestRoundTripper(t *testing.T, testCase roundTripperTestCase) testRou
receivedBodyBytes, err = io.ReadAll(req.Body)
require.NoError(t, err)
}
require.Equal(t, testCase.expectedBody, string(receivedBodyBytes), "roundTripperTestCase body do not match")
require.Equal(t, testCase.expectedBody, string(receivedBodyBytes), "roundTripperTestCase received unexpected body")
}

body := bytes.NewBuffer([]byte(testCase.sendResponseBody))
return &http.Response{StatusCode: testCase.sendStatusCode, Body: io.NopCloser(body)}
}
}

type conditionalTestCase struct {
expectedHost string
expectedPath string
expectedMethod string

// responses map an expected body to the output that should be sent
responses map[string]sendResponse
}

type sendResponse struct {
statusCode int
body string
}

func createConditionalTestRoundTripper(t *testing.T, testCase conditionalTestCase) testRoundTripper {
t.Helper()

require.True(t, len(testCase.responses) > 0, "no responses defined")

return func(req *http.Request) *http.Response {
t.Helper()

assert.Equal(t, testCase.expectedHost, req.URL.Host)
assert.Equal(t, testCase.expectedPath, req.URL.Path)

require.NotNil(t, req.Body, "roundTripperTestCase received nil body")

gotBody, err := io.ReadAll(req.Body)
require.NoError(t, err)
defer req.Body.Close()

require.Containsf(t, testCase.responses, string(gotBody), "received unexpected body: %v", string(gotBody))
response := testCase.responses[string(gotBody)]
return &http.Response{
StatusCode: response.statusCode,
Body: io.NopCloser(bytes.NewBuffer([]byte(response.body))),
}
}
}

func stringify(any interface{}) []byte {
out, _ := json.Marshal(any)
return out
Expand Down
Loading
Loading