MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestNetwork_CompileErrors

Function TestNetwork_CompileErrors

ext/network_test.go:655–735  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

653}
654
655func TestNetwork_CompileErrors(t *testing.T) {
656 tests := []struct {
657 name string
658 expr string
659 errContains string
660 }{
661 {
662 name: "ip constructor invalid literal",
663 expr: "ip('999.999.999.999')",
664 errContains: "invalid ip argument",
665 },
666 {
667 name: "cidr constructor invalid literal",
668 expr: "cidr('1.2.3.4')",
669 errContains: "invalid cidr argument",
670 },
671 {
672 name: "cidr constructor invalid mask literal",
673 expr: "cidr('10.0.0.0/999')",
674 errContains: "invalid cidr argument",
675 },
676 {
677 name: "ip constructor valid literal",
678 expr: "ip('127.0.0.1')",
679 errContains: "",
680 },
681 {
682 name: "cidr constructor valid literal",
683 expr: "cidr('10.0.0.0/8')",
684 errContains: "",
685 },
686 {
687 name: "passing cidr into isIP returns compile error",
688 expr: "isIP(cidr('192.168.0.0/24'))",
689 errContains: "found no matching overload for 'isIP'",
690 },
691 {
692 name: "cidr parse invalid ipv4",
693 expr: "cidr('192.168.0.0/')",
694 errContains: "invalid cidr argument",
695 },
696 {
697 name: "cidr parse invalid ipv6",
698 expr: "cidr('2001:db8::/')",
699 errContains: "invalid cidr argument",
700 },
701 }
702
703 env, err := cel.NewEnv(Network())
704 if err != nil {
705 t.Fatalf("cel.NewEnv(Network()) failed: %v", err)
706 }
707
708 for _, tst := range tests {
709 t.Run(tst.name, func(t *testing.T) {
710 _, iss := env.Compile(tst.expr)
711 if tst.errContains != "" {
712 if iss.Err() == nil {

Callers

nothing calls this directly

Calls 5

CompileMethod · 0.95
NewEnvFunction · 0.92
NetworkFunction · 0.85
ErrMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected