Skip to content

Commit

Permalink
test(server): health api
Browse files Browse the repository at this point in the history
  • Loading branch information
RyushiAok committed Nov 1, 2023
1 parent 19e54c7 commit 645b47c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 11 deletions.
7 changes: 7 additions & 0 deletions server/server.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EFD2C1B2-081
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Api", "src\Api\Api.fsproj", "{2C9B3F27-74E1-4232-9B3F-A64A7285388C}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Test", "src\Test\Test.fsproj", "{86360191-F5CF-453A-BC27-344763F6C971}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -20,8 +22,13 @@ Global
{2C9B3F27-74E1-4232-9B3F-A64A7285388C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C9B3F27-74E1-4232-9B3F-A64A7285388C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C9B3F27-74E1-4232-9B3F-A64A7285388C}.Release|Any CPU.Build.0 = Release|Any CPU
{86360191-F5CF-453A-BC27-344763F6C971}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86360191-F5CF-453A-BC27-344763F6C971}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86360191-F5CF-453A-BC27-344763F6C971}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86360191-F5CF-453A-BC27-344763F6C971}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2C9B3F27-74E1-4232-9B3F-A64A7285388C} = {EFD2C1B2-081A-4AF9-98FD-7CDDDDA3C0C0}
{86360191-F5CF-453A-BC27-344763F6C971} = {EFD2C1B2-081A-4AF9-98FD-7CDDDDA3C0C0}
EndGlobalSection
EndGlobal
12 changes: 1 addition & 11 deletions server/src/Api/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,7 @@ type Program =


[<EntryPoint>]
let main args =
let isTest = args.Length > 0 && args[0] = "test"

printfn "isTest: %b" isTest

let env = {
env with
environment = if isTest then "test" else env.environment
}


let main _ =
let errorHandler = Api.Handler.errorHandler true

let repos = {
Expand Down
1 change: 1 addition & 0 deletions server/src/Test/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Program = let [<EntryPoint>] main _ = 0
36 changes: 36 additions & 0 deletions server/src/Test/Test.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<Compile Include="Tests.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FsHttp" Version="11.0.0" />
<PackageReference Include="Fsunit.Xunit" Version="5.5.0" />
<PackageReference Include="microsoft.AspNetCore.Mvc.Testing" Version="7.0.13" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Api\Api.fsproj" />
</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions server/src/Test/Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Tests

open Xunit
open FsHttp
open System.Net
open FsUnit.Xunit
open Microsoft.AspNetCore.Mvc.Testing

let webapp = new WebApplicationFactory<Program.Program>()
let client = webapp.CreateClient()

[<Fact>]
let health () =

let resp =
client.GetAsync("/health")
|> Async.AwaitTask
|> Async.RunSynchronously

resp.StatusCode |> should equal HttpStatusCode.OK

0 comments on commit 645b47c

Please sign in to comment.