This repository has been archived by the owner on Sep 17, 2022. It is now read-only.
-
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
8 changed files
with
126 additions
and
96 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 |
---|---|---|
@@ -1,22 +1,36 @@ | ||
package matcher | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/getapid/apid/log" | ||
) | ||
|
||
type boolMatcher struct { | ||
value bool | ||
} | ||
|
||
func BoolMatcher(value bool) Matcher { | ||
return boolMatcher{value} | ||
func BoolMatcherWithOptions(params interface{}) Matcher { | ||
switch v := params.(type) { | ||
case bool: | ||
return boolMatcher{v} | ||
default: | ||
log.L.Fatalf("invalid bool matcher, got %v", params) | ||
} | ||
return nil | ||
} | ||
|
||
func (m boolMatcher) Match(data interface{}, location string) (bool, []string, []string) { | ||
// switch val := data.(type) { | ||
// case bool: | ||
// return v.value == val, "" | ||
// } | ||
// return false, "" | ||
return false, nil, nil | ||
switch val := data.(type) { | ||
case bool: | ||
if m.value == val { | ||
return true, []string{fmt.Sprintf("%s is %t", location, m.value)}, nil | ||
} | ||
} | ||
|
||
return false, nil, []string{fmt.Sprintf("%s: wanted %t, got %v", location, m.value, data)} | ||
} | ||
|
||
func (m boolMatcher) String() string { | ||
return "false" | ||
return fmt.Sprintf("%t", m.value) | ||
} |
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,24 @@ | ||
package matcher | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type typeBoolMatcher struct{} | ||
|
||
func TypeBoolMatcherWithOptions(value interface{}) Matcher { | ||
return &typeBoolMatcher{} | ||
} | ||
|
||
func (m typeBoolMatcher) Match(data interface{}, location string) (bool, []string, []string) { | ||
switch data.(type) { | ||
case bool: | ||
return true, []string{fmt.Sprintf("%s is bool", location)}, nil | ||
} | ||
|
||
return false, nil, []string{fmt.Sprintf("%s wanted bool, got %v", location, data)} | ||
} | ||
|
||
func (m typeBoolMatcher) String() string { | ||
return "type::bool" | ||
} |
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,59 @@ | ||
local vars = import 'vars.libsonnet'; | ||
|
||
local text_body_spec(method, body, expectedBody) = std.manifestJson( | ||
{ | ||
steps: [ | ||
{ | ||
name: 'first request', | ||
request: { | ||
method: method, | ||
url: vars.url, | ||
body: body, | ||
}, | ||
expect: { | ||
code: 200, | ||
body: expectedBody, | ||
}, | ||
}, | ||
{ | ||
name: 'second request', | ||
request: { | ||
method: method, | ||
url: vars.url, | ||
body: body, | ||
}, | ||
expect: { | ||
code: 200, | ||
body: expectedBody, | ||
}, | ||
}, | ||
], | ||
} | ||
); | ||
|
||
{ | ||
['true-bool-%s-%s-%s' % [method, body, expectedBody]]: text_body_spec(method, body, expectedBody) | ||
for method in ['POST', 'PUT', 'PATCH', 'DELETE'] | ||
for body in [true] | ||
for expectedBody in [ | ||
false, | ||
] | ||
} | ||
{ | ||
['false-bool-%s-%s-%s' % [method, body, expectedBody]]: text_body_spec(method, body, expectedBody) | ||
for method in ['POST', 'PUT', 'PATCH', 'DELETE'] | ||
for body in [false] | ||
for expectedBody in [ | ||
true, | ||
] | ||
} | ||
{ | ||
['non-bool-%s-%s-%s' % [method, body, expectedBody]]: text_body_spec(method, body, expectedBody) | ||
for method in ['POST', 'PUT', 'PATCH', 'DELETE'] | ||
for body in ['false', 12, 13.1247, {}, []] | ||
for expectedBody in [ | ||
type.bool, | ||
false, | ||
true, | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
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