Skip to content

Commit

Permalink
Add http response rule matching tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pondzix committed Aug 7, 2024
1 parent f01e1ae commit bd1edd1
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions pkg/target/http_response_rules_test.go
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)
}

0 comments on commit bd1edd1

Please sign in to comment.