-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Includes initial specs laid out in #95 - Add F#-friendly serialization via FSharp.System.Text.Json - Add tests
- Loading branch information
Showing
6 changed files
with
367 additions
and
3 deletions.
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
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,104 @@ | ||
namespace ARCExpect | ||
|
||
open Expecto | ||
open System.Text.Json | ||
open System.IO | ||
|
||
/// <summary> | ||
/// Represents a brief summary of the result of validating an ARC against a set of validation cases. | ||
/// </summary> | ||
type ValidationResult = { | ||
HasFailures: bool | ||
Total: int | ||
Passed: int | ||
Failed: int | ||
Errored: int | ||
} with | ||
static member create( | ||
hasFailures: bool, | ||
total: int, | ||
passed: int, | ||
failed: int, | ||
errored: int | ||
) = { | ||
HasFailures = hasFailures | ||
Total = total | ||
Passed = passed | ||
Failed = failed | ||
Errored = errored | ||
} | ||
|
||
static member create (total: int, passed: int, failed: int, errored: int) = | ||
ValidationResult.create( | ||
hasFailures = (failed > 0 || errored > 0), | ||
total = total, | ||
passed = passed, | ||
failed = failed, | ||
errored = errored | ||
) | ||
|
||
static member ofTestRunSummary (summary: Impl.TestRunSummary) = | ||
|
||
let totalTests = summary.errored @ summary.failed @ summary.ignored @ summary.passed | ||
|
||
ValidationResult.create( | ||
total = totalTests.Length, | ||
passed = summary.passed.Length, | ||
errored = summary.errored.Length, | ||
failed = summary.failed.Length | ||
) | ||
|
||
/// <summary> | ||
/// Represents a brief summary of a validation package. Should be expanded to include full package metadata in the future. | ||
/// </summary> | ||
type ValidationPackageSummary = { | ||
Name: string | ||
Version: string | ||
HookEndpoint: string option | ||
} with | ||
static member create( | ||
name: string, | ||
version: string, | ||
?HookEndpoint: string | ||
) = { | ||
Name = name | ||
Version = version | ||
HookEndpoint = HookEndpoint | ||
} | ||
|
||
/// <summary> | ||
/// Represents a summary of the validation results of an ARC against a validation package containing critical and non-critical validation cases. | ||
/// </summary> | ||
type ValidationSummary = { | ||
Critical: ValidationResult | ||
NonCritical: ValidationResult | ||
ValidationPackage: ValidationPackageSummary | ||
} with | ||
static member create( | ||
critical: ValidationResult, | ||
nonCritical: ValidationResult, | ||
validationPackage: ValidationPackageSummary | ||
) = { | ||
Critical = critical | ||
NonCritical = nonCritical | ||
ValidationPackage = validationPackage | ||
} | ||
static member ofTestRunSummaries ( | ||
criticalSummary: Impl.TestRunSummary, | ||
nonCriticalSummary: Impl.TestRunSummary, | ||
package: ValidationPackageSummary | ||
) = | ||
ValidationSummary.create( | ||
critical = ValidationResult.ofTestRunSummary criticalSummary, | ||
nonCritical = ValidationResult.ofTestRunSummary nonCriticalSummary, | ||
validationPackage = package | ||
) | ||
|
||
static member toJson (summary: ValidationSummary) = | ||
JsonSerializer.Serialize(summary, JsonOptions.options) | ||
|
||
static member fromJson (json: string) = | ||
JsonSerializer.Deserialize<ValidationSummary>(json, JsonOptions.options) | ||
|
||
static member writeJson (path: string) (summary: ValidationSummary) = | ||
File.WriteAllText(path, ValidationSummary.toJson summary) |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
module ReferenceObjects | ||
|
||
open ControlledVocabulary | ||
open ARCExpect | ||
|
||
module CvTerms = | ||
|
||
|
@@ -16,4 +17,98 @@ module CvParams = | |
|
||
let ``Investigation Person Email (valid)`` = CvParam(CvTerms.``Investigation Person Email``, ParamValue.Value "[email protected]") | ||
|
||
let ``Investigation Person Email (invalid)`` = CvParam(CvTerms.``Investigation Person Email``, ParamValue.Value "nope") | ||
let ``Investigation Person Email (invalid)`` = CvParam(CvTerms.``Investigation Person Email``, ParamValue.Value "nope") | ||
|
||
module ValidationResult = | ||
|
||
let allPassed = { | ||
HasFailures = false | ||
Total = 1 | ||
Passed = 1 | ||
Failed = 0 | ||
Errored = 0 | ||
} | ||
|
||
let allFailed = { | ||
HasFailures = true | ||
Total = 1 | ||
Passed = 0 | ||
Failed = 1 | ||
Errored = 0 | ||
} | ||
|
||
module ValidationPackageSummary = | ||
|
||
let noHook = { | ||
Name = "test" | ||
Version = "1.0.0" | ||
HookEndpoint = None | ||
} | ||
|
||
let withHook = { | ||
Name = "test" | ||
Version = "1.0.0" | ||
HookEndpoint = Some "http://test.com" | ||
} | ||
|
||
module ValidationSummary = | ||
|
||
let allPassedNoHook = | ||
{ | ||
Critical = ValidationResult.allPassed | ||
NonCritical = ValidationResult.allPassed | ||
ValidationPackage = ValidationPackageSummary.noHook | ||
} | ||
|
||
let allPassedNoHookJson = """{"Critical":{"HasFailures":false,"Total":1,"Passed":1,"Failed":0,"Errored":0},"NonCritical":{"HasFailures":false,"Total":1,"Passed":1,"Failed":0,"Errored":0},"ValidationPackage":{"Name":"test","Version":"1.0.0"}}""" | ||
|
||
let allPassedWithHook = | ||
{ | ||
Critical = ValidationResult.allPassed | ||
NonCritical = ValidationResult.allPassed | ||
ValidationPackage = ValidationPackageSummary.withHook | ||
} | ||
|
||
let allPassedWithHookJson = """{"Critical":{"HasFailures":false,"Total":1,"Passed":1,"Failed":0,"Errored":0},"NonCritical":{"HasFailures":false,"Total":1,"Passed":1,"Failed":0,"Errored":0},"ValidationPackage":{"Name":"test","Version":"1.0.0","HookEndpoint":"http://test.com"}}""" | ||
|
||
let allFailedNoHook = | ||
{ | ||
Critical = ValidationResult.allFailed | ||
NonCritical = ValidationResult.allFailed | ||
ValidationPackage = ValidationPackageSummary.noHook | ||
} | ||
|
||
let allFailedWithHook = | ||
{ | ||
Critical = ValidationResult.allFailed | ||
NonCritical = ValidationResult.allFailed | ||
ValidationPackage = ValidationPackageSummary.withHook | ||
} | ||
|
||
let nonCriticalFailedNoHook = | ||
{ | ||
Critical = ValidationResult.allPassed | ||
NonCritical = ValidationResult.allFailed | ||
ValidationPackage = ValidationPackageSummary.noHook | ||
} | ||
|
||
let nonCriticalFailedWithHook = | ||
{ | ||
Critical = ValidationResult.allPassed | ||
NonCritical = ValidationResult.allFailed | ||
ValidationPackage = ValidationPackageSummary.withHook | ||
} | ||
|
||
let criticalFailedNoHook = | ||
{ | ||
Critical = ValidationResult.allFailed | ||
NonCritical = ValidationResult.allPassed | ||
ValidationPackage = ValidationPackageSummary.noHook | ||
} | ||
|
||
let criticalFailedWithHook = | ||
{ | ||
Critical = ValidationResult.allFailed | ||
NonCritical = ValidationResult.allPassed | ||
ValidationPackage = ValidationPackageSummary.withHook | ||
} |
Oops, something went wrong.