mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-10 18:48:44 +00:00
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package expressions
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/google/cel-go/common/types"
|
|
)
|
|
|
|
func TestURLValues(t *testing.T) {
|
|
headers := URLValues{
|
|
Values: url.Values{
|
|
"format": {"json"},
|
|
},
|
|
}
|
|
|
|
t.Run("contains-existing-key", func(t *testing.T) {
|
|
resp := headers.Contains(types.String("format"))
|
|
if !bool(resp.(types.Bool)) {
|
|
t.Fatal("headers does not contain User-Agent")
|
|
}
|
|
})
|
|
|
|
t.Run("not-contains-missing-key", func(t *testing.T) {
|
|
resp := headers.Contains(types.String("not-there"))
|
|
if bool(resp.(types.Bool)) {
|
|
t.Fatal("headers does not contain User-Agent")
|
|
}
|
|
})
|
|
|
|
t.Run("get-existing-key", func(t *testing.T) {
|
|
val := headers.Get(types.String("format"))
|
|
switch val.(type) {
|
|
case types.String:
|
|
// ok
|
|
default:
|
|
t.Fatalf("result was wrong type %T", val)
|
|
}
|
|
})
|
|
|
|
t.Run("not-get-missing-key", func(t *testing.T) {
|
|
val := headers.Get(types.String("not-there"))
|
|
switch val.(type) {
|
|
case *types.Err:
|
|
// ok
|
|
default:
|
|
t.Fatalf("result was wrong type %T", val)
|
|
}
|
|
})
|
|
}
|