-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: various edge cases in targeting (#1041)
- returning variants from targeting which are not in the variants list is now an error - minor spec changes --------- Signed-off-by: Todd Baert <[email protected]> Co-authored-by: Michael Beemer <[email protected]>
- Loading branch information
Showing
10 changed files
with
261 additions
and
118 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 |
---|---|---|
|
@@ -55,13 +55,13 @@ func TestFractionalEvaluation(t *testing.T) { | |
} | ||
|
||
tests := map[string]struct { | ||
flags Flags | ||
flagKey string | ||
context map[string]any | ||
expectedValue string | ||
expectedVariant string | ||
expectedReason string | ||
expectedError error | ||
flags Flags | ||
flagKey string | ||
context map[string]any | ||
expectedValue string | ||
expectedVariant string | ||
expectedReason string | ||
expectedErrorCode string | ||
}{ | ||
"[email protected]": { | ||
flags: flags, | ||
|
@@ -247,38 +247,6 @@ func TestFractionalEvaluation(t *testing.T) { | |
expectedValue: "#FF0000", | ||
expectedReason: model.DefaultReason, | ||
}, | ||
"fallback to default variant if invalid variant as result of fractional evaluation": { | ||
flags: Flags{ | ||
Flags: map[string]model.Flag{ | ||
"headerColor": { | ||
State: "ENABLED", | ||
DefaultVariant: "red", | ||
Variants: map[string]any{ | ||
"red": "#FF0000", | ||
"blue": "#0000FF", | ||
"green": "#00FF00", | ||
"yellow": "#FFFF00", | ||
}, | ||
Targeting: []byte(`{ | ||
"fractional": [ | ||
{"var": "email"}, | ||
[ | ||
"black", | ||
100 | ||
] | ||
] | ||
}`), | ||
}, | ||
}, | ||
}, | ||
flagKey: "headerColor", | ||
context: map[string]any{ | ||
"email": "[email protected]", | ||
}, | ||
expectedVariant: "red", | ||
expectedValue: "#FF0000", | ||
expectedReason: model.DefaultReason, | ||
}, | ||
"fallback to default variant if percentages don't sum to 100": { | ||
flags: Flags{ | ||
Flags: map[string]model.Flag{ | ||
|
@@ -379,8 +347,11 @@ func TestFractionalEvaluation(t *testing.T) { | |
t.Errorf("expected reason '%s', got '%s'", tt.expectedReason, reason) | ||
} | ||
|
||
if err != tt.expectedError { | ||
t.Errorf("expected err '%v', got '%v'", tt.expectedError, err) | ||
if err != nil { | ||
errorCode := err.Error() | ||
if errorCode != tt.expectedErrorCode { | ||
t.Errorf("expected err '%v', got '%v'", tt.expectedErrorCode, err) | ||
} | ||
} | ||
}) | ||
} | ||
|
@@ -433,13 +404,13 @@ func BenchmarkFractionalEvaluation(b *testing.B) { | |
} | ||
|
||
tests := map[string]struct { | ||
flags Flags | ||
flagKey string | ||
context map[string]any | ||
expectedValue string | ||
expectedVariant string | ||
expectedReason string | ||
expectedError error | ||
flags Flags | ||
flagKey string | ||
context map[string]any | ||
expectedValue string | ||
expectedVariant string | ||
expectedReason string | ||
expectedErrorCode string | ||
}{ | ||
"[email protected]": { | ||
flags: flags, | ||
|
@@ -509,8 +480,11 @@ func BenchmarkFractionalEvaluation(b *testing.B) { | |
b.Errorf("expected reason '%s', got '%s'", tt.expectedReason, reason) | ||
} | ||
|
||
if err != tt.expectedError { | ||
b.Errorf("expected err '%v', got '%v'", tt.expectedError, err) | ||
if err != nil { | ||
errorCode := err.Error() | ||
if errorCode != tt.expectedErrorCode { | ||
b.Errorf("expected err '%v', got '%v'", tt.expectedErrorCode, err) | ||
} | ||
} | ||
} | ||
}) | ||
|
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 |
---|---|---|
|
@@ -55,13 +55,13 @@ func TestLegacyFractionalEvaluation(t *testing.T) { | |
} | ||
|
||
tests := map[string]struct { | ||
flags Flags | ||
flagKey string | ||
context map[string]any | ||
expectedValue string | ||
expectedVariant string | ||
expectedReason string | ||
expectedError error | ||
flags Flags | ||
flagKey string | ||
context map[string]any | ||
expectedValue string | ||
expectedVariant string | ||
expectedReason string | ||
expectedErrorCode string | ||
}{ | ||
"[email protected]": { | ||
flags: flags, | ||
|
@@ -188,11 +188,12 @@ func TestLegacyFractionalEvaluation(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
flagKey: "headerColor", | ||
context: map[string]any{}, | ||
expectedVariant: "red", | ||
expectedValue: "#FF0000", | ||
expectedReason: model.DefaultReason, | ||
flagKey: "headerColor", | ||
context: map[string]any{}, | ||
expectedVariant: "", | ||
expectedValue: "", | ||
expectedReason: model.ErrorReason, | ||
expectedErrorCode: model.ParseErrorCode, | ||
}, | ||
"fallback to default variant if invalid variant as result of fractional evaluation": { | ||
flags: Flags{ | ||
|
@@ -222,9 +223,10 @@ func TestLegacyFractionalEvaluation(t *testing.T) { | |
context: map[string]any{ | ||
"email": "[email protected]", | ||
}, | ||
expectedVariant: "red", | ||
expectedValue: "#FF0000", | ||
expectedReason: model.DefaultReason, | ||
expectedVariant: "", | ||
expectedValue: "", | ||
expectedReason: model.ErrorReason, | ||
expectedErrorCode: model.ParseErrorCode, | ||
}, | ||
"fallback to default variant if percentages don't sum to 100": { | ||
flags: Flags{ | ||
|
@@ -291,8 +293,11 @@ func TestLegacyFractionalEvaluation(t *testing.T) { | |
t.Errorf("expected reason '%s', got '%s'", tt.expectedReason, reason) | ||
} | ||
|
||
if err != tt.expectedError { | ||
t.Errorf("expected err '%v', got '%v'", tt.expectedError, err) | ||
if err != nil { | ||
errorCode := err.Error() | ||
if errorCode != tt.expectedErrorCode { | ||
t.Errorf("expected err '%v', got '%v'", tt.expectedErrorCode, err) | ||
} | ||
} | ||
}) | ||
} | ||
|
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
Oops, something went wrong.