Skip to content

Commit 5ee8148

Browse files
authored
Use go-httpbin in the integration test (#22)
closes #21 Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
1 parent 267fc6c commit 5ee8148

4 files changed

Lines changed: 23 additions & 7 deletions

File tree

integration/envoy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,5 @@ static_resources:
158158
- endpoint:
159159
address:
160160
socket_address:
161-
address: httpbin.org
162-
port_value: 80
161+
address: 127.0.0.1
162+
port_value: 1234

integration/go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ module github.com/envoyproxy/dynamic-modules-examples/integration
22

33
go 1.24.0
44

5-
require github.com/stretchr/testify v1.10.0
5+
require (
6+
github.com/mccutchen/go-httpbin/v2 v2.18.0
7+
github.com/stretchr/testify v1.10.0
8+
)
69

710
require (
811
github.com/davecgh/go-spew v1.1.1 // indirect

integration/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/mccutchen/go-httpbin/v2 v2.18.0 h1:WFU1OELp3nHYLvXct/3nrGVIgxU0X+RJfDPYRBnvicY=
4+
github.com/mccutchen/go-httpbin/v2 v2.18.0/go.mod h1:GBy5I7XwZ4ZLhT3hcq39I4ikwN9x4QUt6EAxNiR8Jus=
35
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
46
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
57
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=

integration/main_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15+
"github.com/mccutchen/go-httpbin/v2/httpbin"
1516
"github.com/stretchr/testify/require"
1617
)
1718

@@ -21,6 +22,16 @@ func TestIntegration(t *testing.T) {
2122
cwd, err := os.Getwd()
2223
require.NoError(t, err)
2324

25+
// Setup the httpbin upstream local server.
26+
httpbinHandler := httpbin.New()
27+
server := &http.Server{Addr: ":1234", Handler: httpbinHandler}
28+
go func() {
29+
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
30+
t.Logf("HTTP server error: %v", err)
31+
}
32+
}()
33+
t.Cleanup(func() { _ = server.Close() })
34+
2435
// Create a directory for the access logs to be written to.
2536
accessLogsDir := cwd + "/access_logs"
2637
require.NoError(t, os.RemoveAll(accessLogsDir))
@@ -140,15 +151,15 @@ func TestIntegration(t *testing.T) {
140151
t.Logf("response: headers=%v, body=%s", resp.Header, string(body))
141152
require.Equal(t, 200, resp.StatusCode)
142153

143-
// HttpBin returns a JSON object containing the request headers.
154+
// HttpBin returns a JSON object containing the request headers in this format.
144155
type httpBinHeadersBody struct {
145-
Headers map[string]string `json:"headers"`
156+
Headers map[string][]string `json:"headers"`
146157
}
147158
var headersBody httpBinHeadersBody
148159
require.NoError(t, json.Unmarshal(body, &headersBody))
149160

150-
require.Equal(t, "envoy-header", headersBody.Headers["X-Envoy-Header"])
151-
require.Equal(t, "envoy-header2", headersBody.Headers["X-Envoy-Header2"])
161+
require.Contains(t, headersBody.Headers["X-Envoy-Header"], "envoy-header")
162+
require.Contains(t, headersBody.Headers["X-Envoy-Header2"], "envoy-header2")
152163
require.NotContains(t, headersBody.Headers, "apple")
153164

154165
// We also need to check that the response headers were mutated.

0 commit comments

Comments
 (0)