ce7cb702218693d08ea6d83464d2457c9250027c
This commit is contained in:
commit
34c5f8963c
1 changed files with 145336 additions and 0 deletions
52
services/bot-redirect/tests.fsx
Normal file
52
services/bot-redirect/tests.fsx
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#load "bots.fsx"
|
||||
|
||||
open System.Text.Json
|
||||
open Bots
|
||||
|
||||
let bot =
|
||||
{ Slug = "test"
|
||||
Patterns = [ " Bot/1.0" ]
|
||||
Examples = [ "Bot/1.0"; "Alternate/1.0"; "Browser" ]
|
||||
Signer = Some "https://agent.example.test/keys" }
|
||||
|
||||
let matches = headers (Set.singleton "Browser") bot
|
||||
assert (matches.Length = 3)
|
||||
|
||||
assert
|
||||
(matches
|
||||
|> List.exists (fun header -> header.Kind = "Exact" && header.Value = "Alternate/1.0"))
|
||||
|
||||
assert
|
||||
(matches
|
||||
|> List.exists (fun header ->
|
||||
header.Name = "Signature-Agent"
|
||||
&& header.Value = "\"https://agent.example.test/keys\""))
|
||||
|
||||
assert (matches |> List.forall (fun header -> header.Value <> "Browser"))
|
||||
|
||||
let config =
|
||||
JsonDocument.Parse(
|
||||
"""{"namespace":"test","gateway":"relay","gatewayNamespace":"test","source":"git.example.test","target":"code.example.test"}"""
|
||||
)
|
||||
|
||||
let many =
|
||||
[ for index in 0..128 ->
|
||||
{ Name = "User-Agent"
|
||||
Kind = "Exact"
|
||||
Value = string index } ]
|
||||
|
||||
let output = routes config.RootElement many
|
||||
assert (output.Length = 2)
|
||||
assert (output.Head.spec.rules.Length = 2)
|
||||
assert (output.Head.spec.rules.Head.matches.Length = 64)
|
||||
assert (output.Tail.Head.spec.rules.Head.matches.Length = 1)
|
||||
let encoded = JsonDocument.Parse(JsonSerializer.Serialize output)
|
||||
|
||||
assert
|
||||
(encoded.RootElement[0]
|
||||
.GetProperty("metadata")
|
||||
.GetProperty("labels")
|
||||
.GetProperty("app.kubernetes.io/managed-by")
|
||||
.GetString() = "bot-redirect")
|
||||
|
||||
printfn "bot matching and route partition tests passed"
|
||||
Loading…
Reference in a new issue