-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add constant comparison operator to jq evaluation #4512
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,11 +42,11 @@ func NewJQEvaluator(assertions []*pb.RuleType_Definition_Eval_JQComparison) (*Ev | |
|
||
for idx := range assertions { | ||
a := assertions[idx] | ||
if a.Profile == nil { | ||
return nil, fmt.Errorf("missing profile accessor") | ||
if a.Profile == nil && a.Constant == nil { | ||
return nil, fmt.Errorf("missing profile or constant accessor") | ||
} | ||
|
||
if a.Profile.Def == "" { | ||
if a.Profile != nil && a.Profile.Def == "" { | ||
return nil, fmt.Errorf("missing profile accessor definition") | ||
} | ||
|
||
|
@@ -72,14 +72,25 @@ func (jqe *Evaluator) Eval(ctx context.Context, pol map[string]any, res *engif.R | |
obj := res.Object | ||
|
||
for idx := range jqe.assertions { | ||
var profileVal, dataVal any | ||
var expectedVal, dataVal any | ||
var err error | ||
|
||
a := jqe.assertions[idx] | ||
profileVal, err := util.JQReadFrom[any](ctx, a.Profile.Def, pol) | ||
// we ignore util.ErrNoValueFound because we want to allow the JQ accessor to return the default value | ||
// which is fine for DeepEqual | ||
if err != nil && !errors.Is(err, util.ErrNoValueFound) { | ||
return fmt.Errorf("cannot get values from profile accessor: %w", err) | ||
|
||
// If there is no profile accessor, get the expected value from the constant accessor | ||
if a.Profile == nil { | ||
expectedVal, err = util.JQReadConstant[any](a.Constant.AsInterface()) | ||
if err != nil { | ||
return fmt.Errorf("cannot get values from profile accessor: %w", err) | ||
} | ||
} else { | ||
// Get the expected value from the profile accessor | ||
expectedVal, err = util.JQReadFrom[any](ctx, a.Profile.Def, pol) | ||
// we ignore util.ErrNoValueFound because we want to allow the JQ accessor to return the default value | ||
// which is fine for DeepEqual | ||
if err != nil && !errors.Is(err, util.ErrNoValueFound) { | ||
return fmt.Errorf("cannot get values from profile accessor: %w", err) | ||
} | ||
} | ||
|
||
dataVal, err = util.JQReadFrom[any](ctx, a.Ingested.Def, obj) | ||
|
@@ -88,9 +99,9 @@ func (jqe *Evaluator) Eval(ctx context.Context, pol map[string]any, res *engif.R | |
} | ||
|
||
// Deep compare | ||
if !reflect.DeepEqual(profileVal, dataVal) { | ||
if !reflect.DeepEqual(numberToFloat64(expectedVal), numberToFloat64(dataVal)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this work for booleans (like your example)? I believe you that it does, but I was surprised to see that it worked. Oh, I see! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the name |
||
msg := fmt.Sprintf("data does not match profile: for assertion %d, got %v, want %v", | ||
idx, dataVal, profileVal) | ||
idx, dataVal, expectedVal) | ||
|
||
marshalledAssertion, err := json.MarshalIndent(a, "", " ") | ||
if err == nil { | ||
|
@@ -103,3 +114,21 @@ func (jqe *Evaluator) Eval(ctx context.Context, pol map[string]any, res *engif.R | |
|
||
return nil | ||
} | ||
|
||
// Convert numeric types to float64 | ||
func numberToFloat64(v any) any { | ||
switch v := v.(type) { | ||
case int: | ||
return float64(v) | ||
case int32: | ||
return float64(v) | ||
case int64: | ||
return float64(v) | ||
case float32: | ||
return float64(v) | ||
case float64: | ||
return v | ||
default: | ||
return v | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"testing" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/stretchr/testify/assert" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"google.golang.org/protobuf/types/known/structpb" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
evalerrors "github.com/stacklok/minder/internal/engine/errors" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/stacklok/minder/internal/engine/eval/jq" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -65,8 +66,10 @@ func TestNewJQEvaluatorValid(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Profile: &pb.RuleType_Definition_Eval_JQComparison_Operator{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Def: ".b", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constant: &structpb.Value{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Kind: &structpb.Value_StringValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
StringValue: "b", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ingested: &pb.RuleType_Definition_Eval_JQComparison_Operator{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Def: ".b", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -111,11 +114,12 @@ func TestNewJQEvaluatorInvalid(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "invalid nil profile accessor", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "invalid nil profile and constant accessor", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
args: args{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertions: []*pb.RuleType_Definition_Eval_JQComparison{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Profile: nil, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Profile: nil, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constant: nil, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ingested: &pb.RuleType_Definition_Eval_JQComparison_Operator{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Def: ".", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -229,6 +233,27 @@ func TestValidJQEvals(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "valid single rule evaluates constant string", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertions: []*pb.RuleType_Definition_Eval_JQComparison{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constant: &structpb.Value{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Kind: &structpb.Value_StringValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
StringValue: "simple", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ingested: &pb.RuleType_Definition_Eval_JQComparison_Operator{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Def: ".simple", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
args: args{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pol: map[string]any{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
obj: map[string]any{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"simple": "simple", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "valid single rule evaluates int", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertions: []*pb.RuleType_Definition_Eval_JQComparison{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -250,6 +275,27 @@ func TestValidJQEvals(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "valid single rule evaluates constant int", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertions: []*pb.RuleType_Definition_Eval_JQComparison{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constant: &structpb.Value{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Kind: &structpb.Value_NumberValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
NumberValue: 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ingested: &pb.RuleType_Definition_Eval_JQComparison_Operator{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Def: ".simple", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
args: args{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pol: map[string]any{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
obj: map[string]any{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"simple": 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "valid single rule evaluates bool", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertions: []*pb.RuleType_Definition_Eval_JQComparison{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -271,6 +317,27 @@ func TestValidJQEvals(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "valid single rule evaluates constant bool", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertions: []*pb.RuleType_Definition_Eval_JQComparison{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constant: &structpb.Value{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Kind: &structpb.Value_BoolValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BoolValue: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can write this as:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ingested: &pb.RuleType_Definition_Eval_JQComparison_Operator{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Def: ".simple", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
args: args{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pol: map[string]any{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
obj: map[string]any{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"simple": false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "valid single rule evaluates array", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertions: []*pb.RuleType_Definition_Eval_JQComparison{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -292,6 +359,45 @@ func TestValidJQEvals(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "valid single rule evaluates constant array", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertions: []*pb.RuleType_Definition_Eval_JQComparison{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constant: &structpb.Value{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Kind: &structpb.Value_ListValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ListValue: &structpb.ListValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Values: []*structpb.Value{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Kind: &structpb.Value_StringValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
StringValue: "a", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Kind: &structpb.Value_StringValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
StringValue: "b", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Kind: &structpb.Value_StringValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
StringValue: "c", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love that we're testing list input. 🎉 Again, I think the helpers in
Suggested change
Unfortunately, |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ingested: &pb.RuleType_Definition_Eval_JQComparison_Operator{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Def: ".simple", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
args: args{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pol: map[string]any{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
obj: map[string]any{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"simple": []any{"a", "b", "c"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for _, tt := range tests { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tt := tt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -447,6 +553,77 @@ func TestValidJQEvalsFailed(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "constant value doesn't match", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertions: []*pb.RuleType_Definition_Eval_JQComparison{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constant: &structpb.Value{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Kind: &structpb.Value_BoolValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BoolValue: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ingested: &pb.RuleType_Definition_Eval_JQComparison_Operator{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Def: ".simple", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
args: args{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pol: map[string]any{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
obj: map[string]any{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"simple": false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "constant type doesn't match", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertions: []*pb.RuleType_Definition_Eval_JQComparison{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constant: &structpb.Value{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Kind: &structpb.Value_BoolValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BoolValue: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ingested: &pb.RuleType_Definition_Eval_JQComparison_Operator{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Def: ".simple", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
args: args{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pol: map[string]any{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
obj: map[string]any{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"simple": 123, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "constant array doesn't match", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertions: []*pb.RuleType_Definition_Eval_JQComparison{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constant: &structpb.Value{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Kind: &structpb.Value_ListValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ListValue: &structpb.ListValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Values: []*structpb.Value{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Kind: &structpb.Value_StringValue{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
StringValue: "a", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ingested: &pb.RuleType_Definition_Eval_JQComparison_Operator{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Def: ".simple", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
args: args{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pol: map[string]any{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
obj: map[string]any{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"simple": []any{"a", "b", "d"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for _, tt := range tests { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tt := tt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want
Profile
andConstant
to be XOR (at least one set, but not both)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I've updated it