Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions test/unit/cel_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package unit

import (
"errors"
"testing"

"github.com/sivchari/govalid/test"
Expand Down Expand Up @@ -52,6 +53,46 @@ func TestCELValidation(t *testing.T) {
},
expectError: false,
},
{
name: "age below minimum",
data: test.CEL{
Age: 17,
Name: "John",
Score: 50.0,
IsActive: true,
},
expectError: true,
},
{
name: "age at minimum boundary",
data: test.CEL{
Age: 18,
Name: "John",
Score: 50.0,
IsActive: true,
},
expectError: false,
},
{
name: "empty name",
data: test.CEL{
Age: 25,
Name: "",
Score: 50.0,
IsActive: true,
},
expectError: true,
},
{
name: "is_active false",
data: test.CEL{
Age: 25,
Name: "John",
Score: 50.0,
IsActive: false,
},
expectError: true,
},
}

for _, tt := range tests {
Expand All @@ -75,6 +116,17 @@ func TestCELValidation(t *testing.T) {
}
}

func TestCELValidationNil(t *testing.T) {
// Test with nil pointer
err := test.ValidateCEL(nil)
if err == nil {
t.Error("expected error for nil CEL, got nil")
}
if !errors.Is(err, test.ErrNilCEL) {
t.Errorf("expected 'input CEL is nil', got %v", err.Error())
}
}

func TestCELCrossFieldValidation(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading