mirror of
https://github.com/Smaug123/gitea-repo-config
synced 2025-10-08 17:08:40 +00:00
Add tests (#60)
This commit is contained in:
34
Gitea.Declarative.Test/Logging.fs
Normal file
34
Gitea.Declarative.Test/Logging.fs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace Gitea.Declarative.Test
|
||||
|
||||
open System
|
||||
open Microsoft.Extensions.Logging
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module LoggerFactory =
|
||||
|
||||
/// Creates a test ILoggerFactory, a sink whose provided inputs you can access through the `unit -> string list`.
|
||||
let makeTest () : ILoggerFactory * (unit -> string list) =
|
||||
let outputs = ResizeArray<_> ()
|
||||
|
||||
let lf =
|
||||
{ new ILoggerFactory with
|
||||
member _.Dispose () = ()
|
||||
|
||||
member _.CreateLogger (name : string) =
|
||||
{ new ILogger with
|
||||
member _.IsEnabled _ = true
|
||||
|
||||
member _.BeginScope _ =
|
||||
{ new IDisposable with
|
||||
member _.Dispose () = ()
|
||||
}
|
||||
|
||||
member _.Log (_, _, state, exc : exn, formatter) =
|
||||
let toWrite = formatter.Invoke (state, exc)
|
||||
lock outputs (fun () -> outputs.Add toWrite)
|
||||
}
|
||||
|
||||
member _.AddProvider provider = failwith "unsupported"
|
||||
}
|
||||
|
||||
lf, (fun () -> lock outputs (fun () -> Seq.toList outputs))
|
Reference in New Issue
Block a user