forked from TykTechnologies/tyk
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix trace request builder func (TykTechnologies#3262)
When `tr.Path` was empty, it was giving error. So I change `httptest.NewRequest()` to `http.NewRequest()`. Fixes TykTechnologies/tyk-analytics#2031
- Loading branch information
1 parent
931118f
commit 49161a3
Showing
2 changed files
with
37 additions
and
6 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
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 @@ | ||
package gateway | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTraceHttpRequest_toRequest(t *testing.T) { | ||
const body = `{"foo":"bar"}` | ||
header := http.Header{} | ||
header.Add("key", "value") | ||
tr := &traceHttpRequest{Path: "", Method: http.MethodPost, Body: body, Headers: header} | ||
|
||
request, err := tr.toRequest() | ||
bodyInBytes, _ := ioutil.ReadAll(request.Body) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, http.MethodPost, request.Method) | ||
assert.Equal(t, "", request.URL.Host) | ||
assert.Equal(t, "", request.URL.Path) | ||
assert.Equal(t, header, request.Header) | ||
assert.Equal(t, string(bodyInBytes), body) | ||
} |