-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AVPRIndex: Fix line endings mattering for package content hash
- AVPRIndex: normalize line endings to \n before creating checksum for indexed packages AVPRIndex: unify some creat functions - add tests
- Loading branch information
Showing
9 changed files
with
234 additions
and
39 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
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,41 @@ | ||
namespace DomainTests | ||
|
||
open System | ||
open System.IO | ||
open Xunit | ||
open AVPRIndex | ||
open AVPRIndex.Domain | ||
open ReferenceObjects | ||
|
||
module Author = | ||
|
||
[<Fact>] | ||
let ``create function for mandatory fields``() = | ||
let actual = Author.create(fullName = "test") | ||
Assert.Equivalent(Author.mandatoryFields, actual) | ||
|
||
[<Fact>] | ||
let ``create function for all fields``() = | ||
let actual = Author.create( | ||
fullName = "test", | ||
Email = "[email protected]", | ||
Affiliation = "testaffiliation", | ||
AffiliationLink = "test.com" | ||
) | ||
Assert.Equivalent(Author.allFields, actual) | ||
|
||
module OntologyAnnotation = | ||
|
||
[<Fact>] | ||
let ``create function for mandatory fields``() = | ||
let actual = OntologyAnnotation.create(name = "test") | ||
Assert.Equivalent(OntologyAnnotation.mandatoryFields, actual) | ||
|
||
[<Fact>] | ||
let ``create function for all fields``() = | ||
let actual = OntologyAnnotation.create( | ||
name = "test", | ||
TermSourceREF = "REF", | ||
TermAccessionNumber = "TAN" | ||
) | ||
Assert.Equivalent(OntologyAnnotation.allFields, actual) |
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,8 +1,33 @@ | ||
module ReferenceObjects | ||
|
||
open Utils | ||
open AVPRIndex | ||
open AVPRIndex.Domain | ||
|
||
let testDate = System.DateTimeOffset.Parse("01/01/2024") | ||
|
||
module Author = | ||
|
||
let mandatoryFields = Author(FullName = "test") | ||
|
||
let allFields = | ||
Author( | ||
FullName = "test", | ||
Email = "[email protected]", | ||
Affiliation = "testaffiliation", | ||
AffiliationLink = "test.com" | ||
) | ||
|
||
module OntologyAnnotation = | ||
|
||
let mandatoryFields = OntologyAnnotation(Name = "test") | ||
|
||
let allFields = OntologyAnnotation( | ||
Name = "test", | ||
TermSourceREF = "REF", | ||
TermAccessionNumber = "TAN" | ||
) | ||
|
||
module Frontmatter = | ||
|
||
let validMandatoryFrontmatter = """(* | ||
|
@@ -210,4 +235,33 @@ It does it very fast, it does it very swell. | |
It does it very good, it does it very well. | ||
It does it very fast, it does it very swell. | ||
""".ReplaceLineEndings("\n") | ||
) | ||
|
||
module ValidationPackageIndex = | ||
|
||
let validMandatoryFrontmatter = | ||
ValidationPackageIndex.create( | ||
repoPath = "fixtures/[email protected]", | ||
fileName = "[email protected]", | ||
lastUpdated = testDate, | ||
contentHash = (Frontmatter.validMandatoryFrontmatter |> md5hash), | ||
metadata = Metadata.validMandatoryFrontmatter | ||
) | ||
|
||
let validFullFrontmatter = | ||
ValidationPackageIndex.create( | ||
repoPath = "fixtures/[email protected]", | ||
fileName = "[email protected]", | ||
lastUpdated = testDate, | ||
contentHash = (Frontmatter.validFullFrontmatter |> md5hash), | ||
metadata = Metadata.validFullFrontmatter | ||
) | ||
|
||
let invalidMissingMandatoryFrontmatter = | ||
ValidationPackageIndex.create( | ||
repoPath = "fixtures/[email protected]", | ||
fileName = "[email protected]", | ||
lastUpdated = testDate, | ||
contentHash = (Frontmatter.invalidMissingMandatoryFrontmatter |> md5hash), | ||
metadata = Metadata.invalidMissingMandatoryFrontmatter | ||
) |
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,16 +1,103 @@ | ||
namespace ValidationPackageIndexTests | ||
|
||
open System | ||
open System.IO | ||
open Xunit | ||
open AVPRIndex | ||
open AVPRIndex.Domain | ||
open AVPRIndex.Frontmatter | ||
open Utils | ||
open ReferenceObjects | ||
|
||
module InMemory = | ||
module IO = | ||
|
||
open System.IO | ||
|
||
[<Fact>] | ||
let ``My test`` () = | ||
Assert.True(true) | ||
let ``valid indexed package is extracted from valid mandatory field test file`` () = | ||
|
||
module IO = | ||
let actual = | ||
ValidationPackageIndex.create( | ||
repoPath = "fixtures/[email protected]", | ||
lastUpdated = testDate | ||
) | ||
Assert.Equivalent(ValidationPackageIndex.validMandatoryFrontmatter, actual) | ||
|
||
|
||
[<Fact>] | ||
let ``valid indexed package is extracted from all fields test file`` () = | ||
|
||
let actual = | ||
ValidationPackageIndex.create( | ||
repoPath = "fixtures/[email protected]", | ||
lastUpdated = testDate | ||
) | ||
Assert.Equivalent(ValidationPackageIndex.validFullFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``invalid indexed package is extracted from testfile with missing fields`` () = | ||
|
||
let actual = | ||
ValidationPackageIndex.create( | ||
repoPath = "fixtures/[email protected]", | ||
lastUpdated = testDate | ||
) | ||
Assert.Equivalent(ValidationPackageIndex.invalidMissingMandatoryFrontmatter, actual) | ||
|
||
[<Fact>] | ||
let ``CRLF: correct content hash (with line endings replaced) is extracted from valid mandatory field test file`` () = | ||
let tmp_path = Path.GetTempFileName() | ||
File.WriteAllText( | ||
tmp_path, | ||
Frontmatter.validMandatoryFrontmatter.ReplaceLineEndings("\r\n") | ||
) | ||
let actual = | ||
ValidationPackageIndex.create( | ||
repoPath = tmp_path, | ||
lastUpdated = testDate | ||
) | ||
let expected = { | ||
ValidationPackageIndex.validMandatoryFrontmatter with | ||
RepoPath = tmp_path | ||
FileName = Path.GetFileName(tmp_path) | ||
} | ||
Assert.Equivalent(expected, actual) | ||
|
||
|
||
[<Fact>] | ||
let ``CRLF: correct content hash (with line endings replaced) is extracted from all fields test file`` () = | ||
let tmp_path = Path.GetTempFileName() | ||
File.WriteAllText( | ||
tmp_path, | ||
Frontmatter.validFullFrontmatter.ReplaceLineEndings("\r\n") | ||
) | ||
let actual = | ||
ValidationPackageIndex.create( | ||
repoPath = tmp_path, | ||
lastUpdated = testDate | ||
) | ||
let expected = { | ||
ValidationPackageIndex.validFullFrontmatter with | ||
RepoPath = tmp_path | ||
FileName = Path.GetFileName(tmp_path) | ||
} | ||
Assert.Equivalent(expected, actual) | ||
|
||
[<Fact>] | ||
let ``My test`` () = | ||
Assert.True(true) | ||
let ```CRLF: correct content hash (with line endings replaced) is extracted from testfile with missing fields`` () = | ||
let tmp_path = Path.GetTempFileName() | ||
File.WriteAllText( | ||
tmp_path, | ||
Frontmatter.invalidMissingMandatoryFrontmatter.ReplaceLineEndings("\r\n") | ||
) | ||
let actual = | ||
ValidationPackageIndex.create( | ||
repoPath = tmp_path, | ||
lastUpdated = testDate | ||
) | ||
let expected = { | ||
ValidationPackageIndex.invalidMissingMandatoryFrontmatter with | ||
RepoPath = tmp_path | ||
FileName = Path.GetFileName(tmp_path) | ||
} | ||
Assert.Equivalent(expected, actual) |