-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add http response rule matching tests
- Loading branch information
Showing
1 changed file
with
78 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,78 @@ | ||
/** | ||
* Copyright (c) 2020-present Snowplow Analytics Ltd. | ||
* All rights reserved. | ||
* | ||
* This software is made available by Snowplow Analytics, Ltd., | ||
* under the terms of the Snowplow Limited Use License Agreement, Version 1.0 | ||
* located at https://docs.snowplow.io/limited-use-license-1.0 | ||
* BY INSTALLING, DOWNLOADING, ACCESSING, USING OR DISTRIBUTING ANY PORTION | ||
* OF THE SOFTWARE, YOU AGREE TO THE TERMS OF SUCH LICENSE AGREEMENT. | ||
*/ | ||
|
||
package target | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHTTP_Rules_StatusMatch(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
response := response{Status: 500, Body: "Invalid field 'attribute'"} | ||
rules := []Rule{ | ||
{MatchingHTTPCodes: []int{500, 503}}, | ||
} | ||
|
||
matchingRule := findMatchingRule(response, rules) | ||
assert.Equal(&rules[0], matchingRule) | ||
} | ||
|
||
func TestHTTP_Rules_FullBodyMatch(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
response := response{Status: 500, Body: "Invalid field 'attribute'"} | ||
rules := []Rule{ | ||
{MatchingHTTPCodes: []int{500, 503}, MatchingBodyPart: "Invalid field 'attribute'"}, | ||
} | ||
|
||
matchingRule := findMatchingRule(response, rules) | ||
assert.Equal(&rules[0], matchingRule) | ||
} | ||
|
||
func TestHTTP_Rules_PartialBodyMatch(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
response := response{Status: 500, Body: "Invalid field 'attribute'"} | ||
rules := []Rule{ | ||
{MatchingHTTPCodes: []int{500, 503}, MatchingBodyPart: "Invalid field"}, | ||
} | ||
|
||
matchingRule := findMatchingRule(response, rules) | ||
assert.Equal(&rules[0], matchingRule) | ||
} | ||
|
||
func TestHTTP_Rules_StatusMatch_NoBodyMatch(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
response := response{Status: 500, Body: "Invalid field 'attribute'"} | ||
rules := []Rule{ | ||
{MatchingHTTPCodes: []int{500, 503}, MatchingBodyPart: "Invalid field 'events'"}, | ||
} | ||
|
||
matchingRule := findMatchingRule(response, rules) | ||
assert.Nil(matchingRule) | ||
} | ||
|
||
func TestHTTP_Rules_NoStatusMatch_BodyMatch(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
response := response{Status: 500, Body: "Invalid field 'attribute'"} | ||
rules := []Rule{ | ||
{MatchingHTTPCodes: []int{503}, MatchingBodyPart: "Invalid field"}, | ||
} | ||
|
||
matchingRule := findMatchingRule(response, rules) | ||
assert.Nil(matchingRule) | ||
} |