Skip to content

Commit

Permalink
Add latest metadata additions from package registry, adapt test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Feb 23, 2024
1 parent bd114be commit 0345f28
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 7 deletions.
88 changes: 84 additions & 4 deletions src/ARCValidationPackages/Domain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,119 @@ open System.IO
open System.Text.Json
open System.Text.Json.Serialization

// must be a class to be deserializable with YamlDotNet

// must be classes to be deserializable with YamlDotNet

/// <summary>
/// Represents the author of a validation package
/// </summary>
type Author() =
// mandatory fields
member val FullName = "" with get,set
member val Email = "" with get,set
// optional fields
member val Affiliation = "" with get,set
member val AffiliationLink = "" with get,set

override this.GetHashCode() = hash (this.FullName, this.Email, this.Affiliation, this.AffiliationLink)

override this.Equals(other) =
match other with
| :? Author as a ->
(this.FullName, this.Email, this.Affiliation, this.AffiliationLink) = (a.FullName, a.Email, a.Affiliation, a.AffiliationLink)
| _ -> false

static member create(
fullName: string,
email: string,
?Affiliation: string,
?AffiliationLink: string
) =
let tmp = Author()
tmp.FullName <- fullName
tmp.Email <- email
Affiliation |> Option.iter (fun x -> tmp.Affiliation <- x)
AffiliationLink |> Option.iter (fun x -> tmp.AffiliationLink <- x)
tmp


/// <summary>
/// Represents the metadata of a validation package, e.g. version, name and description.
/// </summary>
type ValidationPackageMetadata() =
// mandatory fields
member val Name = "" with get,set
member val Description = "" with get,set
member val MajorVersion = 0 with get,set
member val MinorVersion = 0 with get,set
member val PatchVersion = 0 with get,set
// optional fields
member val Publish = false with get,set
member val Authors: Author [] = Array.empty<Author> with get,set
member val Tags: string [] = Array.empty<string> with get,set
member val ReleaseNotes = "" with get,set

override this.GetHashCode() =
hash (this.Name, this.Description, this.MajorVersion, this.MinorVersion, this.PatchVersion)
hash (
this.Name,
this.Description,
this.MajorVersion,
this.MinorVersion,
this.PatchVersion,
this.Publish,
this.Authors,
this.Tags,
this.ReleaseNotes
)

override this.Equals(other) =
match other with
| :? ValidationPackageMetadata as vpm ->
(this.Name, this.Description, this.MajorVersion, this.MinorVersion, this.PatchVersion) = (vpm.Name, vpm.Description, vpm.MajorVersion, vpm.MinorVersion, vpm.PatchVersion)
(
this.Name,
this.Description,
this.MajorVersion,
this.MinorVersion,
this.PatchVersion,
this.Publish,
this.Authors,
this.Tags,
this.ReleaseNotes
) = (
vpm.Name,
vpm.Description,
vpm.MajorVersion,
vpm.MinorVersion,
vpm.PatchVersion,
vpm.Publish,
vpm.Authors,
vpm.Tags,
vpm.ReleaseNotes
)
| _ -> false

static member create (
name: string,
description: string,
majorVersion: int,
minorVersion: int,
patchVersion: int
patchVersion: int,
?Publish: bool,
?Authors: Author [],
?Tags: string [],
?ReleaseNotes
) =
let tmp = ValidationPackageMetadata()
tmp.Name <- name
tmp.Description <- description
tmp.MajorVersion <- majorVersion
tmp.MinorVersion <- minorVersion
tmp.PatchVersion <- patchVersion
Publish |> Option.iter (fun x -> tmp.Publish <- x)
Authors |> Option.iter (fun x -> tmp.Authors <- x)
Tags |> Option.iter (fun x -> tmp.Tags <- x)
ReleaseNotes |> Option.iter (fun x -> tmp.ReleaseNotes <- x)

tmp

static member getSemanticVersionString(m: ValidationPackageMetadata) = $"{m.MajorVersion}.{m.MinorVersion}.{m.PatchVersion}";
Expand Down
38 changes: 37 additions & 1 deletion tests/ARCValidationPackages.Tests/ReferenceObjects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open TestUtils

let testDate1 = System.DateTimeOffset.ParseExact("2023-08-15 10:00:00 +02:00", "yyyy-MM-dd HH:mm:ss zzz", System.Globalization.CultureInfo.InvariantCulture)
let testDate2 = System.DateTimeOffset.ParseExact("2023-08-15 11:00:00 +02:00", "yyyy-MM-dd HH:mm:ss zzz", System.Globalization.CultureInfo.InvariantCulture)

let testDate3 = System.DateTimeOffset.ParseExact("2024-02-22 09:00:17 +01:00", "yyyy-MM-dd HH:mm:ss zzz", System.Globalization.CultureInfo.InvariantCulture)

let testPackageIndex =
[|
Expand All @@ -29,6 +29,7 @@ Description: this package is here for testing purposes only.
MajorVersion: 1
MinorVersion: 0
PatchVersion: 0
Publish: true
---
*)
Expand All @@ -51,6 +52,41 @@ let testValidationPackage2 =
ValidationPackageMetadata.create("test", "this package is here for testing purposes only.", 1, 0, 0)
)

let testValidationPackage3FullMetadata =
ARCValidationPackage.create(
"test@3.0.0.fsx",
testDate3,
(Path.Combine(expected_package_cache_folder_path, "test@3.0.0.fsx").Replace("\\","/")),
ValidationPackageMetadata.create(
"test",
"this package is here for testing purposes only.",
1,
0,
0,
Publish = true,
Authors = [|
Author.create(
fullName = "John Doe",
email = "j@d.com",
Affiliation = "University of Nowhere",
AffiliationLink = "https://nowhere.edu"
)
Author.create(
fullName = "Jane Doe",
email = "jj@d.com",
Affiliation = "University of Somewhere",
AffiliationLink = "https://somewhere.edu"
)
|],
Tags = [|
"validation"
"my-package"
"thing"
|],
ReleaseNotes = "add authors and tags for further testing"
)
)

let testPackageCache1 = PackageCache([testValidationPackage1])
let testPackageCache2 = PackageCache([testValidationPackage2])

Expand Down
4 changes: 2 additions & 2 deletions tests/arc-validate.Tests/CLITests/ValidateCommandTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let ``ValidateCommand CLI Tests`` =
(get_gh_api_token())
) [
"Package script exists after running package install test" ,
fun tool args proc -> Expect.isTrue (File.Exists(Path.Combine(expected_package_cache_folder_path, "test@2.0.0.fsx"))) (ErrorMessage.withCLIDiagnostics "package file was not installed at expected location" tool args )
fun tool args proc -> Expect.isTrue (File.Exists(Path.Combine(expected_package_cache_folder_path, "test@3.0.0.fsx"))) (ErrorMessage.withCLIDiagnostics "package file was not installed at expected location" tool args )
]
yield!
testFixture (Fixtures.withToolExecution
Expand All @@ -67,7 +67,7 @@ let ``ValidateCommand CLI Tests`` =
"Console output does not indicate that package is not installed" ,
fun tool args proc -> Expect.isFalse (proc.Result.Output.Contains("Package test not installed. You can run run arc-validate package install ")) (ErrorMessage.withProcessDiagnostics "incorrect console output" proc tool args )
"Console Output is correct" ,
fun tool args proc -> Expect.isTrue (proc.Result.Output.Contains("Hello, world!")) (ErrorMessage.withProcessDiagnostics "incorrect console output" proc tool args )
fun tool args proc -> Expect.isTrue (proc.Result.Output.Contains("If you can read this in your console, you successfully executed test package v3.0.0!")) (ErrorMessage.withProcessDiagnostics "incorrect console output" proc tool args )

]
])
Expand Down
2 changes: 2 additions & 0 deletions tests/arc-validate.Tests/ReferenceObjects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Description: this package is here for testing purposes only.
MajorVersion: 1
MinorVersion: 0
PatchVersion: 0
Publish: true
---
*)
Expand All @@ -26,6 +27,7 @@ Name: test
MajorVersion: 2
MinorVersion: 0
PatchVersion: 0
Publish: true
Description: this package is here for testing purposes only.
Authors:
- FullName: John Doe
Expand Down

0 comments on commit 0345f28

Please sign in to comment.