github.com/expr-lang/expr@v1.16.9/test/coredns/coredns_test.go (about) 1 package coredns_test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/expr-lang/expr/internal/testify/assert" 8 9 "github.com/expr-lang/expr" 10 "github.com/expr-lang/expr/test/coredns" 11 ) 12 13 func TestCoreDNS(t *testing.T) { 14 env := coredns.DefaultEnv(context.Background(), &coredns.Request{}) 15 16 tests := []struct { 17 input string 18 }{ 19 {`metadata('geoip/city/name') == 'Exampleshire'`}, 20 {`(type() == 'A' && name() == 'example.com') || client_ip() == '1.2.3.4'`}, 21 {`name() matches '^abc\\..*\\.example\\.com\\.$'`}, 22 {`type() in ['A', 'AAAA']`}, 23 {`incidr(client_ip(), '192.168.0.0/16')`}, 24 {`incidr(client_ip(), '127.0.0.0/24')`}, 25 } 26 27 for _, test := range tests { 28 t.Run(test.input, func(t *testing.T) { 29 _, err := expr.Compile(test.input, expr.Env(env), expr.DisableBuiltin("type")) 30 assert.NoError(t, err) 31 }) 32 } 33 }