Skip to content

Commit

Permalink
Update regression tests to use local httpbin, test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Tit Petric committed Sep 11, 2024
1 parent d5b9366 commit f26934b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/regression/issue_10104_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func Test_Issue10104(t *testing.T) {
ts := gateway.StartTest(nil)
defer ts.Close()
t.Cleanup(ts.Close)

// load api definition from file
ts.Gw.LoadAPI(loadAPISpec(t, "testdata/issue-10104-apidef.json"))
Expand Down
4 changes: 2 additions & 2 deletions tests/regression/issue_11585_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func Test_Issue11585_DeleteAPICacheSignal(t *testing.T) {
t.Run("redis event", func(t *testing.T) {
ts := gateway.StartTest(nil)
defer ts.Close()
t.Cleanup(ts.Close)

api := ts.Gw.BuildAndLoadAPI(func(spec *gateway.APISpec) {
spec.UseKeylessAccess = true
Expand Down Expand Up @@ -49,7 +49,7 @@ func Test_Issue11585_DeleteAPICacheSignal(t *testing.T) {

t.Run("rpc", func(t *testing.T) {
ts := gateway.StartTest(nil)
defer ts.Close()
t.Cleanup(ts.Close)

rpcListener := gateway.RPCStorageHandler{
KeyPrefix: "rpc.listener.",
Expand Down
14 changes: 7 additions & 7 deletions tests/regression/issue_11806_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Test_Issue11806_DomainRouting(t *testing.T) {

t.Run("Load listenPath without domain first", func(t *testing.T) {
ts := gateway.StartTest(testConfig)
defer ts.Close()
t.Cleanup(ts.Close)

ts.Gw.LoadAPI(noDomain, withDomain)

Expand All @@ -34,7 +34,7 @@ func Test_Issue11806_DomainRouting(t *testing.T) {

t.Run("Load listenPath with domain first", func(t *testing.T) {
ts := gateway.StartTest(testConfig)
defer ts.Close()
t.Cleanup(ts.Close)

ts.Gw.LoadAPI(withDomain, noDomain)

Expand Down Expand Up @@ -62,10 +62,10 @@ func testDomainRouting(tb testing.TB, ts *gateway.Test) {
},
{
Path: "/test/",
Host: "customer.mydomain.com",
Host: "example.com",
Method: http.MethodGet,
Code: http.StatusOK,
BodyMatch: "customer.mydomain.com",
BodyMatch: "example.com",
},
}...)
}
Expand All @@ -80,7 +80,7 @@ func testSubrouterHost(t *testing.T) {
ctx := context.Background()

// Create a subrouter with a specific host
subrouter := router.Host("customer.mydomain.com").Subrouter()
subrouter := router.Host("example.com").Subrouter()
subrouter.HandleFunc("/test", func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("Subrouter"))
assert.NoError(t, err)
Expand Down Expand Up @@ -117,7 +117,7 @@ func testSubrouterHost(t *testing.T) {
reqWithSpecificHost, err := http.NewRequestWithContext(ctx, "GET", "/test", nil)
assert.NoError(t, err)

reqWithSpecificHost.Host = "customer.mydomain.com"
reqWithSpecificHost.Host = "example.com"
respWithSpecificHost := httptest.NewRecorder()
router.ServeHTTP(respWithSpecificHost, reqWithSpecificHost)
if respWithSpecificHost.Body.String() != "Subrouter" {
Expand All @@ -131,7 +131,7 @@ func testRouteLongestPathFirst(t *testing.T) {
ts := gateway.StartTest(func(globalConf *config.Config) {
globalConf.EnableCustomDomains = true
})
defer ts.Close()
t.Cleanup(ts.Close)

type hostAndPath struct {
host, path string
Expand Down
4 changes: 4 additions & 0 deletions tests/regression/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package regression
import (
"embed"
"encoding/json"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -25,6 +26,9 @@ func loadAPISpec(tb testing.TB, filename string) *gateway.APISpec {
err := json.Unmarshal(data, apidef)
require.NoError(tb, err, "Error decoding API Definition: %s", filename)

// auto replace from public to private endpoint, part of CI env
apidef.Proxy.ListenPath = strings.ReplaceAll(apidef.Proxy.ListenPath, "httpbin.org", "127.0.0.1:3123")

return &gateway.APISpec{
APIDefinition: apidef,
}
Expand Down

0 comments on commit f26934b

Please sign in to comment.