refactoring tests with mock servers (#30) (#356)

This commit is contained in:
渡邉祐一 / Yuichi Watanabe
2023-06-12 22:40:26 +09:00
committed by GitHub
parent a243e7331f
commit b616090e69
20 changed files with 732 additions and 1061 deletions

View File

@@ -6,7 +6,6 @@ import (
"errors"
"io"
"net/http"
"net/http/httptest"
"os"
"testing"
@@ -226,18 +225,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) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/engines", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusTeapot)
}))
defer ts.Close()
})
config := DefaultConfig("dummy")
config.BaseURL = ts.URL
c := NewClientWithConfig(config)
ctx := context.Background()
_, err = c.ListEngines(ctx)
_, err := client.ListEngines(context.Background())
checks.HasError(t, err, "ListEngines did not fail")
var reqErr *RequestError