2022-06-30 13:20:54 +02:00
|
|
|
package matchers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestValidate(t *testing.T) {
|
|
|
|
|
m := &Matcher{matcherType: DSLMatcher, DSL: []string{"anything"}}
|
|
|
|
|
|
|
|
|
|
err := m.Validate()
|
|
|
|
|
require.Nil(t, err, "Could not validate correct template")
|
|
|
|
|
|
|
|
|
|
m = &Matcher{matcherType: DSLMatcher, Part: "test"}
|
|
|
|
|
err = m.Validate()
|
|
|
|
|
require.NotNil(t, err, "Invalid template was correctly validated")
|
2023-08-26 05:11:51 +12:00
|
|
|
|
|
|
|
|
m = &Matcher{matcherType: XPathMatcher, XPath: []string{"//q[@id=\"foo\"]"}}
|
|
|
|
|
|
|
|
|
|
err = m.Validate()
|
|
|
|
|
require.Nil(t, err, "Could not validate correct XPath template")
|
|
|
|
|
|
|
|
|
|
m = &Matcher{matcherType: XPathMatcher, Status: []int{123}}
|
|
|
|
|
err = m.Validate()
|
|
|
|
|
require.NotNil(t, err, "Invalid XPath template was correctly validated")
|
|
|
|
|
|
|
|
|
|
m = &Matcher{matcherType: XPathMatcher, XPath: []string{"//a[@a==1]"}}
|
|
|
|
|
err = m.Validate()
|
|
|
|
|
require.NotNil(t, err, "Invalid XPath query was correctly validated")
|
2022-06-30 13:20:54 +02:00
|
|
|
}
|