-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4825ffd
commit 196198b
Showing
4 changed files
with
277 additions
and
22 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 |
---|---|---|
|
@@ -8,4 +8,5 @@ inpackage: True | |
packages: | ||
waffle/internal/rule: | ||
interfaces: | ||
Builder: | ||
Builder: | ||
node: |
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,174 @@ | ||
package rule | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/mock" | ||
|
||
"waffle/internal/request" | ||
) | ||
|
||
func Test_and_Eval(t *testing.T) { | ||
type fields struct { | ||
leftFunc func() node | ||
rightFunc func() node | ||
} | ||
type args struct { | ||
r request.Wrapper | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "both nodes true, true returned", | ||
fields: fields{ | ||
leftFunc: func() node { | ||
n := NewMocknode(t) | ||
|
||
n.EXPECT().Eval(mock.Anything).Return(true) | ||
|
||
return n | ||
}, | ||
rightFunc: func() node { | ||
n := NewMocknode(t) | ||
|
||
n.EXPECT().Eval(mock.Anything).Return(true) | ||
|
||
return n | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "one of nodes false, false returned", | ||
fields: fields{ | ||
leftFunc: func() node { | ||
n := NewMocknode(t) | ||
|
||
n.EXPECT().Eval(mock.Anything).Return(true) | ||
|
||
return n | ||
}, | ||
rightFunc: func() node { | ||
n := NewMocknode(t) | ||
|
||
n.EXPECT().Eval(mock.Anything).Return(false) | ||
|
||
return n | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var left, right node | ||
if tt.fields.leftFunc != nil { | ||
left = tt.fields.leftFunc() | ||
} | ||
if tt.fields.rightFunc != nil { | ||
right = tt.fields.rightFunc() | ||
} | ||
|
||
a := and{ | ||
left: left, | ||
right: right, | ||
} | ||
if got := a.Eval(tt.args.r); got != tt.want { | ||
t.Errorf("Eval() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_or_Eval(t *testing.T) { | ||
type fields struct { | ||
leftFunc func() node | ||
rightFunc func() node | ||
} | ||
type args struct { | ||
r request.Wrapper | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "first node true, returns true", | ||
fields: fields{ | ||
leftFunc: func() node { | ||
n := NewMocknode(t) | ||
|
||
n.EXPECT().Eval(mock.Anything).Return(true) | ||
|
||
return n | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "both nodes false, returns false", | ||
fields: fields{ | ||
leftFunc: func() node { | ||
n := NewMocknode(t) | ||
|
||
n.EXPECT().Eval(mock.Anything).Return(false) | ||
|
||
return n | ||
}, | ||
rightFunc: func() node { | ||
n := NewMocknode(t) | ||
|
||
n.EXPECT().Eval(mock.Anything).Return(false) | ||
|
||
return n | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "first node false, second true, returns true", | ||
fields: fields{ | ||
leftFunc: func() node { | ||
n := NewMocknode(t) | ||
|
||
n.EXPECT().Eval(mock.Anything).Return(false) | ||
|
||
return n | ||
}, | ||
rightFunc: func() node { | ||
n := NewMocknode(t) | ||
|
||
n.EXPECT().Eval(mock.Anything).Return(true) | ||
|
||
return n | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var left, right node | ||
if tt.fields.leftFunc != nil { | ||
left = tt.fields.leftFunc() | ||
} | ||
if tt.fields.rightFunc != nil { | ||
right = tt.fields.rightFunc() | ||
} | ||
|
||
o := or{ | ||
left: left, | ||
right: right, | ||
} | ||
if got := o.Eval(tt.args.r); got != tt.want { | ||
t.Errorf("Eval() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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