Skip to content

Commit

Permalink
test: remove httpbin dependency (sashabaranov#297)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
YukiBobier authored May 3, 2023
1 parent 104c0c0 commit 24aa200
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/json"
"errors"
"io"
"net/http"
"net/http/httptest"
"os"
"testing"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 24aa200

Please sign in to comment.