-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add header to skip split by interval
- Loading branch information
1 parent
2fb07a3
commit 573b65e
Showing
5 changed files
with
168 additions
and
1 deletion.
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
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
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,61 @@ | ||
package httpreq | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestQueryNoSplit(t *testing.T) { | ||
for _, tc := range []struct { | ||
desc string | ||
in string | ||
exp bool | ||
error bool | ||
}{ | ||
{ | ||
desc: "true", | ||
in: `true`, | ||
exp: true, | ||
}, | ||
{ | ||
desc: "false", | ||
in: `false`, | ||
exp: false, | ||
}, | ||
{ | ||
desc: "absent", | ||
in: ``, | ||
exp: false, | ||
}, | ||
{ | ||
desc: "garbage", | ||
in: `garbage`, | ||
exp: false, | ||
}, | ||
} { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
req := httptest.NewRequest("GET", "http://testing.com", nil) | ||
if tc.in != "" { | ||
req.Header.Set(string(QueryNoSplitHTTPHeader), tc.in) | ||
} | ||
|
||
w := httptest.NewRecorder() | ||
checked := false | ||
mware := ExtractQueryNoSplitMiddleware().Wrap(http.HandlerFunc(func(_ http.ResponseWriter, req *http.Request) { | ||
noSplit := req.Context().Value(QueryNoSplitHTTPHeader) | ||
noSplitBool, ok := noSplit.(bool) | ||
require.True(t, ok) | ||
require.Equal(t, tc.exp, noSplitBool) | ||
checked = true | ||
})) | ||
|
||
mware.ServeHTTP(w, req) | ||
|
||
assert.True(t, true, checked) | ||
}) | ||
} | ||
} |