summaryrefslogtreecommitdiff
path: root/test/integration/http.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-05-15 09:11:16 -0600
committermo khan <mo@mokhan.ca>2025-05-15 09:11:16 -0600
commit3d01a69471fc4f0ae9f2f4145620b6aea50f2216 (patch)
treef85607ebfb2575bce94b5618250ebd957f965f6e /test/integration/http.go
parent7c75fac3360b8bc3df630b5f8e12b2ff927a2d23 (diff)
parent564e140de454c78d7e6d34044bb78f53bd0b2bf3 (diff)
Merge branch 'envoy-start' into 'main'
Enable Envoy to run consistently locally and in Docker See merge request gitlab-org/software-supply-chain-security/authorization/sparkled!6
Diffstat (limited to 'test/integration/http.go')
-rw-r--r--test/integration/http.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/integration/http.go b/test/integration/http.go
new file mode 100644
index 0000000..20991a2
--- /dev/null
+++ b/test/integration/http.go
@@ -0,0 +1,43 @@
+package test
+
+import (
+ "context"
+ "net/http"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/require"
+ "github.com/xlgmokha/x/pkg/serde"
+)
+
+type testTransport struct {
+ t *testing.T
+}
+
+func (r *testTransport) RoundTrip(request *http.Request) (*http.Response, error) {
+ response, err := http.DefaultTransport.RoundTrip(request)
+ require.NoError(r.t, err)
+ r.t.Logf("%v %v %v\n", response.StatusCode, request.Method, request.URL)
+ return response, err
+}
+
+func HttpGet(t *testing.T, ctx context.Context, path string) *http.Response {
+ client := &http.Client{
+ Timeout: 5 * time.Second,
+ Transport: &testTransport{t: t},
+ }
+
+ request, err := http.NewRequestWithContext(ctx, http.MethodGet, path, nil)
+ require.NoError(t, err)
+
+ response, err := client.Do(request)
+ require.NoError(t, err)
+
+ return response
+}
+
+func JSONBody[T any](t *testing.T, r *http.Response) T {
+ item, err := serde.FromJSON[T](r.Body)
+ require.NoError(t, err)
+ return item
+}