Skip to content

Commit

Permalink
Make staging area tests more robust, do not use binding frontmatter o…
Browse files Browse the repository at this point in the history
…n first suffix test package
  • Loading branch information
kMutagene committed Jun 21, 2024
1 parent a74a26e commit a39258f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 51 deletions.
29 changes: 6 additions & 23 deletions StagingArea/test/[email protected]+suffixes.fsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
let [<Literal>]PACKAGE_METADATA = """(*
(*
---
Name: test
MajorVersion: 5
MinorVersion: 0
PatchVersion: 0
PreRelease: use
BuildMetadata: suffixes
PreReleaseVersionSuffix: use
BuildMetadataVersionSuffix: suffixes
Publish: true
Summary: this package is here for testing purposes only.
Description: this package is here for testing purposes only.
Expand All @@ -22,26 +22,9 @@ Tags:
- Name: validation
- Name: my-package
- Name: thing
ReleaseNotes: Use ARCExpect v3
ReleaseNotes: Use pre-release and build metadata version suffixes
CQCHookEndpoint: https://avpr.nfdi4plants.org
---
*)"""
*)

printfn "If you can read this in your console, you successfully executed test package v5.0.0-use+suffixes!"

#r "nuget: ARCExpect, 3.0.0"

open ARCExpect
open Expecto
let test_package =
Setup.ValidationPackage(
metadata = Setup.Metadata(PACKAGE_METADATA),
CriticalValidationCases = [
test "yes" {Expect.equal 1 1 "yes"}
]
)

test_package
|> Execute.ValidationPipeline(
basePath = System.Environment.CurrentDirectory
)
printfn "If you can read this in your console, you successfully executed test package v5.0.0-use+suffixes!"
14 changes: 10 additions & 4 deletions StagingAreaTests/FileContentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ open System.IO
open Xunit
open Utils

open AVPRIndex

module FileContent =

[<Fact>]
let ``All files have frontmatter`` () =
Assert.All(
ReferenceObjects.all_staged_packages_contents,
snd >> Assert.ContainsFrontmatter
ReferenceObjects.all_staged_packages_paths,
File.ReadAllText >> (fun x -> x.ReplaceLineEndings("\n")) >> Assert.ContainsFrontmatter
)

[<Fact>]
let ``All files have valid metadata`` () =
Assert.All(
ReferenceObjects.all_staged_packages_metadata,
snd >> Assert.MetadataValid
ReferenceObjects.all_staged_packages_paths,
(fun p ->
p
|> ValidationPackageMetadata.extractFromScript
|> Assert.MetadataValid
)
)
7 changes: 4 additions & 3 deletions StagingAreaTests/PackageSanityChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ open System.IO
open Xunit
open Utils

open AVPRIndex

module Metadata =

[<Fact>]
let ``Metadata versions match file names`` () =
Assert.All(
ReferenceObjects.all_staged_packages_metadata,
(fun (path, metadata) ->
ReferenceObjects.all_staged_packages_paths,
(fun path ->
let file_name_version = (Path.GetFileNameWithoutExtension path).Split('@')[1]
let metadata_version = sprintf "%i.%i.%i" metadata.MajorVersion metadata.MinorVersion metadata.PatchVersion
let metadata_version = path |> ValidationPackageMetadata.extractFromScript |> ValidationPackageMetadata.getSemanticVersionString
Assert.Equal(file_name_version, metadata_version)
)
)
Expand Down
16 changes: 1 addition & 15 deletions StagingAreaTests/ReferenceObjects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,4 @@ let all_files_in_staging_area =

let all_staged_packages_paths =
Directory.GetFiles(staging_area_root, "*.fsx", SearchOption.AllDirectories)
|> Array.map (fun x -> x.Replace('\\',Path.DirectorySeparatorChar).Replace('/',Path.DirectorySeparatorChar))

let all_staged_packages_contents =
all_staged_packages_paths
|> Array.map (fun p ->
p,
p |> (File.ReadAllText >> fun x -> x.ReplaceLineEndings("\n"))
)

let all_staged_packages_metadata =
all_staged_packages_paths
|> Array.map (fun p ->
p,
ValidationPackageMetadata.extractFromScript p
)
|> Array.map (fun x -> x.Replace('\\',Path.DirectorySeparatorChar).Replace('/',Path.DirectorySeparatorChar))
2 changes: 1 addition & 1 deletion StagingAreaTests/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ type Assert with
static member FileNameValid(path:string) =
let fileName = Path.GetFileName(path)
let folderName = Path.GetDirectoryName(path) |> Path.GetFileName
let pattern = sprintf @"^%s@\d+\.\d+\.\d+\.fsx$" folderName
let pattern = sprintf @"^%s@%s.fsx$" folderName AVPRIndex.Globals.SEMVER_REGEX_PATTERN[1.. (AVPRIndex.Globals.SEMVER_REGEX_PATTERN.Length - 2)] // first and last characters of that regex are start/end signifiers
Assert.Matches(pattern, fileName)
6 changes: 3 additions & 3 deletions tests/ClientTests/ReferenceObjects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module Hash =
Hash = expected_hash_cqcHookAddition
)

let expected_hash_semVerAddition = "2A546201341641AAB21FB49DADD06676"
let expected_hash_semVerAddition = "E3D3C259C4B3F54783283735B20F8C23"

let allFields_semVerAddition = AVPRClient.PackageContentHash(
PackageName = "name",
Expand Down Expand Up @@ -154,8 +154,8 @@ Description = description
MajorVersion: 1
MinorVersion: 0
PatchVersion: 0
PreRelease: use
BuildMetadata: suffixes
PreReleaseVersionSuffix: use
BuildMetadataVersionSuffix: suffixes
Publish: true
Authors:
- FullName: test
Expand Down
4 changes: 2 additions & 2 deletions tests/ClientTests/fixtures/allFields_semVerAddition.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Description = description
MajorVersion: 1
MinorVersion: 0
PatchVersion: 0
PreRelease: use
BuildMetadata: suffixes
PreReleaseVersionSuffix: use
BuildMetadataVersionSuffix: suffixes
Publish: true
Authors:
- FullName: test
Expand Down

0 comments on commit a39258f

Please sign in to comment.