-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"Disable": [ | ||
"dupl", | ||
"golint", | ||
"gocyclo" | ||
], | ||
"Enable": [ | ||
"structcheck", | ||
"maligned", | ||
"deadcode", | ||
"ineffassign", | ||
"gotype", | ||
"goimports", | ||
"errcheck", | ||
"varcheck", | ||
"interfacer", | ||
"goconst", | ||
"unparam", | ||
"megacheck", | ||
"misspell", | ||
"gas", | ||
"safesql" | ||
], | ||
"LineLength": 120, | ||
"Vendor": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package oaichecker | ||
|
||
import "net/http" | ||
|
||
type Transport struct { | ||
Transport http.RoundTripper | ||
} | ||
|
||
func NewTransport() *Transport { | ||
return &Transport{ | ||
Transport: http.DefaultTransport, | ||
} | ||
} | ||
|
||
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
res, err := t.Transport.RoundTrip(req) | ||
|
||
return res, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package oaichecker | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func resBody(t *testing.T, res *http.Response) string { | ||
body, err := ioutil.ReadAll(res.Body) | ||
require.NoError(t, err) | ||
|
||
return string(body) | ||
} | ||
|
||
func newServer(handlerFunc func(http.ResponseWriter, *http.Request)) *httptest.Server { | ||
return httptest.NewServer(http.HandlerFunc(handlerFunc)) | ||
} | ||
|
||
func Test_Transport_implements_RoundTripper(t *testing.T) { | ||
assert.Implements(t, (*http.RoundTripper)(nil), NewTransport()) | ||
} | ||
|
||
func Test_Transport_emit_the_request(t *testing.T) { | ||
ts := newServer(func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte("some-response")) | ||
}) | ||
defer ts.Close() | ||
|
||
client := http.Client{ | ||
Transport: NewTransport(), | ||
} | ||
|
||
res, err := client.Get(ts.URL) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, "some-response", resBody(t, res)) | ||
} |