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.
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -226,8 +228,13 @@ func TestAPIErrorUnmarshalJSONInvalidMessage(t *testing.T) {
|
|||||||
func TestRequestError(t *testing.T) {
|
func TestRequestError(t *testing.T) {
|
||||||
var err error
|
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 := DefaultConfig("dummy")
|
||||||
config.BaseURL = "https://httpbin.org/status/418?"
|
config.BaseURL = ts.URL
|
||||||
c := NewClientWithConfig(config)
|
c := NewClientWithConfig(config)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
_, err = c.ListEngines(ctx)
|
_, err = c.ListEngines(ctx)
|
||||||
|
|||||||
Reference in New Issue
Block a user