Skip to content

Commit

Permalink
Add Filter Eval testes
Browse files Browse the repository at this point in the history
  • Loading branch information
clementblaise committed Jan 18, 2021
1 parent 83e7525 commit 22cbfda
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions internal/ansible/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ansible

import (
"github.com/go-test/deep"
"github.com/stretchr/testify/assert"
"testing"
)

Expand Down Expand Up @@ -47,3 +48,110 @@ func TestParseFilterArgsFromString(t *testing.T) {
}

}

func TestEval(t *testing.T) {

TestCases := map[string]struct {
given Filter
against string
expect bool
}{
"foo equal foo should pass": {
given: Filter{
Key: "",
Op: Equal,
Value: "foo",
},
against: "foo",
expect: true,
},
"foo equal bar should fail": {
given: Filter{
Key: "",
Op: Equal,
Value: "foo",
},
against: "bar",
expect: false,
},
"foo notequal bar should pass": {
given: Filter{
Key: "",
Op: NotEqual,
Value: "foo",
},
against: "bar",
expect: true,
},
"foo notequal foo should fail": {
given: Filter{
Key: "",
Op: NotEqual,
Value: "foo",
},
against: "foo",
expect: false,
},
"foo endwith oo should pass": {
given: Filter{
Key: "",
Op: EndWith,
Value: "foo",
},
against: "oo",
expect: true,
},
"foo endwith fo should fail": {
given: Filter{
Key: "",
Op: EndWith,
Value: "foo",
},
against: "fo",
expect: false,
},
"foo contains o should pass": {
given: Filter{
Key: "",
Op: Contains,
Value: "foo",
},
against: "o",
expect: true,
},
"foo contains z should fail": {
given: Filter{
Key: "",
Op: Contains,
Value: "foo",
},
against: "z",
expect: false,
},
"foo StartWith fo should pass": {
given: Filter{
Key: "",
Op: StartWith,
Value: "foo",
},
against: "fo",
expect: true,
},
"foo StartWith oo should fail": {
given: Filter{
Key: "",
Op: StartWith,
Value: "foo",
},
against: "oo",
expect: false,
},
}

for testName, testCase := range TestCases {
t.Run(testName, func(t *testing.T) {
result := testCase.given.Eval(testCase.against)
assert.Equal(t, testCase.expect, result)
})
}
}

0 comments on commit 22cbfda

Please sign in to comment.