-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FFM-1452]: Fix bool, int and number comparisons + implement slices
This change fixes the bool, int and number comparisons. It replaces a cast with the appropriate function from the strconv package. The slice type is implemented with support for in, contains and equals operators. Customers can store target attributes as strings, float64, bool and slices. When creating a rule the value is always a slice of strings. The code was trying to cast a string to a int, float etc which does not work. This caused rules evaluations to fail. Added unit tests to verify the type operators now work as expected.
- Loading branch information
1 parent
42cda01
commit 52e6d19
Showing
11 changed files
with
437 additions
and
111 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
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
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,25 @@ | ||
package types | ||
|
||
import "testing" | ||
|
||
func TestBoolean_Equal(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
b Boolean | ||
args []string | ||
want bool | ||
}{ | ||
{"test equal returns true with match", Boolean(true), []string{"true"}, true}, | ||
{"test equal returns false when no match", Boolean(true), []string{"false"}, false}, | ||
{"test equal returns true with multiple values", Boolean(false), []string{"false", "true"}, true}, | ||
{"test equal only matches first value", Boolean(false), []string{"true", "false"}, false}, | ||
{"test equal returns false for invalid value", Boolean(true), []string{"on"}, false}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.b.Equal(tt.args); got != tt.want { | ||
t.Errorf("Equal() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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
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,26 @@ | ||
package types | ||
|
||
import "testing" | ||
|
||
func TestInteger_Equal(t *testing.T) { | ||
|
||
tests := []struct { | ||
name string | ||
n Integer | ||
args []string | ||
want bool | ||
}{ | ||
{"test equal returns true with match", Integer(22), []string{"22"}, true}, | ||
{"test equal returns false when no match", Integer(22), []string{"25"}, false}, | ||
{"test equal returns true with multiple values", Integer(22), []string{"22", "23"}, true}, | ||
{"test equal only matches first value", Integer(22), []string{"23", "22"}, false}, | ||
{"test equal returns false for invalid value", Integer(22), []string{"true"}, false}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.n.Equal(tt.args); got != tt.want { | ||
t.Errorf("Equal() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.