-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] get request headers to params (#65)
- Loading branch information
Showing
3 changed files
with
84 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,14 @@ | ||
request: | ||
method: GET | ||
path: /user-agent | ||
response: | ||
statusCode: 200 | ||
headers: | ||
Content-Type: | ||
- "application/json" | ||
body: > | ||
[ | ||
{ | ||
"user_agent":"{{request.header.User-Agent}}" | ||
} | ||
] |
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,55 @@ | ||
package vars | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/jmartin82/mmock/definition" | ||
) | ||
|
||
func TestGetHeaderParam(t *testing.T) { | ||
rp := Request{} | ||
header := make(definition.Values) | ||
header["Authorization"] = []string{"Bearer abc123"} | ||
req := definition.Request{} | ||
req.Headers = header | ||
rp.Request = &req | ||
v, f := rp.getHeaderParam("Authorization") | ||
if !f { | ||
t.Errorf("Header key not found") | ||
} | ||
|
||
if !strings.EqualFold(v, "Bearer abc123") { | ||
t.Errorf("Couldn't get the content. Value: %s", v) | ||
} | ||
} | ||
|
||
func TestGetHeaderParamNotFoundHeaderKey(t *testing.T) { | ||
rp := Request{} | ||
header := make(definition.Values) | ||
header["Authorization"] = []string{"Bearer abc123"} | ||
req := definition.Request{} | ||
req.Headers = header | ||
rp.Request = &req | ||
_, f := rp.getHeaderParam("Authorization2") | ||
if f { | ||
t.Errorf("Header key found") | ||
} | ||
} | ||
|
||
func TestGetHeaderParamWithOutHeaderValue(t *testing.T) { | ||
rp := Request{} | ||
header := make(definition.Values) | ||
header["Authorization"] = []string{} | ||
req := definition.Request{} | ||
req.Headers = header | ||
rp.Request = &req | ||
v, f := rp.getHeaderParam("Authorization") | ||
if f { | ||
t.Errorf("Header key found") | ||
} | ||
|
||
if strings.EqualFold(v, "Bearer abc1235") { | ||
t.Errorf("Couldn get the content. Value: %s", v) | ||
} | ||
} |