-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multiple values matchers and logical matchers (#14)
- Loading branch information
Showing
12 changed files
with
381 additions
and
262 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
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,54 @@ | ||
package wiremock | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
type LogicalMatcher struct { | ||
operator string | ||
operands []BasicParamMatcher | ||
} | ||
|
||
func (m LogicalMatcher) MarshalJSON() ([]byte, error) { | ||
jsonMap := map[string]interface{}{ | ||
m.operator: m.operands, | ||
} | ||
|
||
return json.Marshal(jsonMap) | ||
} | ||
|
||
// Or returns a logical OR of the current matcher and the given matcher. | ||
func (m LogicalMatcher) Or(matcher BasicParamMatcher) BasicParamMatcher { | ||
if m.operator == "or" { | ||
m.operands = append(m.operands, matcher) | ||
return m | ||
} | ||
|
||
return Or(m, matcher) | ||
} | ||
|
||
// And returns a logical AND of the current matcher and the given matcher. | ||
func (m LogicalMatcher) And(matcher BasicParamMatcher) BasicParamMatcher { | ||
if m.operator == "and" { | ||
m.operands = append(m.operands, matcher) | ||
return m | ||
} | ||
|
||
return And(m, matcher) | ||
} | ||
|
||
// Or returns a logical OR of the list of matchers. | ||
func Or(matchers ...BasicParamMatcher) LogicalMatcher { | ||
return LogicalMatcher{ | ||
operator: "or", | ||
operands: matchers, | ||
} | ||
} | ||
|
||
// And returns a logical AND of the list of matchers. | ||
func And(matchers ...BasicParamMatcher) LogicalMatcher { | ||
return LogicalMatcher{ | ||
operator: "and", | ||
operands: matchers, | ||
} | ||
} |
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,33 @@ | ||
package wiremock | ||
|
||
import "encoding/json" | ||
|
||
type MultiValueMatcher struct { | ||
strategy MultiValueMatchingStrategy | ||
matchers []BasicParamMatcher | ||
} | ||
|
||
// MarshalJSON returns the JSON encoding of the matcher. | ||
func (m MultiValueMatcher) MarshalJSON() ([]byte, error) { | ||
jsonMap := map[string]interface{}{ | ||
string(m.strategy): m.matchers, | ||
} | ||
|
||
return json.Marshal(jsonMap) | ||
} | ||
|
||
// HasExactly returns a matcher that matches when the parameter has exactly the specified values. | ||
func HasExactly(matchers ...BasicParamMatcher) MultiValueMatcher { | ||
return MultiValueMatcher{ | ||
strategy: ParamHasExactly, | ||
matchers: matchers, | ||
} | ||
} | ||
|
||
// Includes returns a matcher that matches when the parameter includes the specified values. | ||
func Includes(matchers ...BasicParamMatcher) MultiValueMatcher { | ||
return MultiValueMatcher{ | ||
strategy: ParamIncludes, | ||
matchers: matchers, | ||
} | ||
} |
Oops, something went wrong.