From 24aa2005ccd849b788a5bfed0d17d9cbcdaf902f Mon Sep 17 00:00:00 2001 From: Yuki Bobier <114851874+YukiBobier@users.noreply.github.com> Date: Thu, 4 May 2023 01:20:32 +0900 Subject: [PATCH] test: remove httpbin dependency (#297) Replace the use of external httpbin service in TestRequestError with a local HTTP server using the net/http/httptest package. This change improves test reliability by eliminating the dependency on an external service. --- api_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api_test.go b/api_test.go index ecba256..78fd5cc 100644 --- a/api_test.go +++ b/api_test.go @@ -5,6 +5,8 @@ import ( "encoding/json" "errors" "io" + "net/http" + "net/http/httptest" "os" "testing" @@ -226,8 +228,13 @@ func TestAPIErrorUnmarshalJSONInvalidMessage(t *testing.T) { func TestRequestError(t *testing.T) { var err error + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusTeapot) + })) + defer ts.Close() + config := DefaultConfig("dummy") - config.BaseURL = "https://httpbin.org/status/418?" + config.BaseURL = ts.URL c := NewClientWithConfig(config) ctx := context.Background() _, err = c.ListEngines(ctx)