-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix EndpointRouting Guid regex + tests (#594)
* fix: guidPattern regex endpoint routing template * tests: add new tests to EndpointRouting * chore: improve test description * tests: add ShortGuid tests * chore: add comment explaining why we use the regex to filter guid routes on %O
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module Giraffe.Tests.EndpointRoutingTests | ||
|
||
open System | ||
open Microsoft.AspNetCore.Builder | ||
open Microsoft.Extensions.DependencyInjection | ||
open Xunit | ||
open Giraffe | ||
open Giraffe.EndpointRouting | ||
open System.Net.Http | ||
|
||
// --------------------------------- | ||
// routef Tests | ||
// --------------------------------- | ||
|
||
[<Theory>] | ||
[<InlineData("00000000-0000-0000-0000-0000000000000", "Not Found")>] | ||
[<InlineData("00000000-0000-0000-0000-000000000000", "Success: 00000000-0000-0000-0000-000000000000")>] | ||
[<InlineData("00000000-0000-0000-0000-00000000000", "Not Found")>] | ||
[<InlineData("0000000000000000000000", "Success: d3344dd3-344d-4dd3-34d3-4d34d34d34d3")>] // ShortGuid | ||
[<InlineData("DBvYFN7y#$@u933Kc8pM#^", "Not Found")>] | ||
[<InlineData("8b3557db-fa-c0c90785ec0b", "Not Found")>] | ||
[<InlineData("8b3557db-fa-c0c90785ec", "Success: e7f9bdf1-5bb7-f6f9-be73-473dd3bf3979")>] // ShortGuid | ||
[<InlineData("8b3557db-fa-c0c90785e", "Not Found")>] | ||
[<InlineData("does-not-make-sense", "Not Found")>] | ||
[<InlineData("1", "Not Found")>] | ||
let ``routef: GET "/try-a-guid/%O" returns "Success: ..." or "Not Found"`` (potentialGuid: string, expected: string) = | ||
task { | ||
let endpoints: Endpoint list = | ||
[ GET | ||
[ route "/" (text "Hello World") | ||
route "/foo" (text "bar") | ||
routef "/try-a-guid/%O" (fun (guid: Guid) -> text $"Success: {guid}") ] ] | ||
|
||
let notFoundHandler = "Not Found" |> text |> RequestErrors.notFound | ||
|
||
let configureApp (app: IApplicationBuilder) = | ||
app.UseRouting() | ||
.UseGiraffe(endpoints) | ||
.UseGiraffe(notFoundHandler) | ||
|
||
let configureServices (services: IServiceCollection) = | ||
services.AddRouting().AddGiraffe() |> ignore | ||
|
||
let request = | ||
createRequest HttpMethod.Get $"/try-a-guid/{potentialGuid}" | ||
|
||
let! response = | ||
makeRequest (fun () -> configureApp) configureServices () request | ||
|
||
let! content = | ||
response |> readText | ||
|
||
content |> shouldEqual expected | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters