Skip to content

Commit

Permalink
fix: bring back ValueFilter.IsEquality and ValueFilter.GetEquality
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffrey Bauduin <geoffrey.bauduin@ovhcloud.com>
  • Loading branch information
geoffreybauduin committed Sep 29, 2020
1 parent aa0bf5e commit 8693fc5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions yaormfilter/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ func TestEquals(t *testing.T) {
assert.IsType(t, &yaormfilter.BoolFilter{}, yaormfilter.Equals(false))
}

func TestEquality(t *testing.T) {
f := yaormfilter.Equals("abdef")
assert.True(t, f.IsEquality())
assert.Equal(t, "abdef", f.GetEquality())

f = yaormfilter.NotEquals("bdef")
assert.False(t, f.IsEquality())
}

func TestNotEquals(t *testing.T) {
assert.IsType(t, &yaormfilter.StringFilter{}, yaormfilter.NotEquals("abcdef"))
assert.IsType(t, &yaormfilter.Int64Filter{}, yaormfilter.NotEquals(int64(12)))
Expand Down
16 changes: 15 additions & 1 deletion yaormfilter/valuefilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,22 @@ type ValueFilter interface {
In(v ...interface{}) ValueFilter
NotIn(v ...interface{}) ValueFilter
Raw(fn RawFilterFunc) ValueFilter
IsEquality() bool
GetEquality() interface{}
}

type valuefilterimpl struct {
filterFn RawFilterFunc
filterFn RawFilterFunc
shouldEqual bool
equals_ interface{}
}

func (f valuefilterimpl) IsEquality() bool {
return f.shouldEqual
}

func (f valuefilterimpl) GetEquality() interface{} {
return f.equals_
}

func (f *valuefilterimpl) nil(v bool) *valuefilterimpl {
Expand All @@ -38,6 +50,8 @@ func (f *valuefilterimpl) nil(v bool) *valuefilterimpl {
}

func (f *valuefilterimpl) equals(e interface{}) *valuefilterimpl {
f.shouldEqual = true
f.equals_ = e
return f.raw(func(field string) interface{} {
return squirrel.Eq{field: e}
})
Expand Down

0 comments on commit 8693fc5

Please sign in to comment.