Skip to content

Commit

Permalink
Use AVPRIndex BinaryContent functions in AVPRClient extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Jun 19, 2024
1 parent bfaa3e7 commit b5c40ee
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/AVPRClient/AVPRClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/RELEASE_NOTES.md"))</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageVersion>0.0.8</PackageVersion>
<PackageVersion>0.0.9</PackageVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<None Include="README.md" Pack="true" PackagePath="\" />
<ProjectReference Include="..\AVPRIndex\AVPRIndex.fsproj" PackageVersion="[0.1.2, 1.0.0)" />
<ProjectReference Include="..\AVPRIndex\AVPRIndex.fsproj" PackageVersion="[0.1.3, 1.0.0)" />
</ItemGroup>

<Target Name="UseExplicitPackageVersions" BeforeTargets="GenerateNuspec">
Expand Down
2 changes: 1 addition & 1 deletion src/AVPRClient/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ DateTimeOffset releaseDate
MajorVersion = indexedPackage.Metadata.MajorVersion,
MinorVersion = indexedPackage.Metadata.MinorVersion,
PatchVersion = indexedPackage.Metadata.PatchVersion,
PackageContent = File.ReadAllBytes(indexedPackage.RepoPath),
PackageContent = BinaryContent.fromFile(indexedPackage.RepoPath),
ReleaseDate = releaseDate,
Tags =
indexedPackage.Metadata.Tags
Expand Down
3 changes: 3 additions & 0 deletions src/AVPRClient/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.0.9
- Use AVPRIndex for all package binary content extractions

## v0.0.8
- Use AVPRIndex for all package hash calculations

Expand Down
54 changes: 34 additions & 20 deletions tests/ClientTests/ReferenceObjects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,9 @@ module ValidationPackageMetadata =
CQCHookEndpoint = "hookendpoint"
)

module PackageContentHash =
open System
open System.IO
open System.Text
open System.Security.Cryptography

let expected_hash =
let md5 = MD5.Create()
"fixtures/test_validation_package_all_fields.fsx"
|> File.ReadAllText
|> fun s -> s.ReplaceLineEndings("\n")
|> Encoding.UTF8.GetBytes
|> md5.ComputeHash
|> Convert.ToHexString
module Hash =

let expected_hash = "C5BD4262301D27CF667106D9024BD721"

let allFields = AVPRClient.PackageContentHash(
PackageName = "name",
Expand All @@ -95,17 +84,42 @@ module PackageContentHash =
PackagePatchVersion = 0,
Hash = expected_hash
)


module ValidationPackage =
module BinaryContent =

open System.IO

let expected_content =
let expected_content = "(*
---
Name: name
Summary: summary
Description = description
MajorVersion: 1
MinorVersion: 0
PatchVersion: 0
Publish: true
Authors:
- FullName: test
Email: [email protected]
Affiliation: testaffiliation
AffiliationLink: test.com
Tags:
- Name: test
TermSourceREF: REF
TermAccessionNumber: TAN
ReleaseNotes: releasenotes
CQCHookEndpoint: hookendpoint
---
*)
printfn \"yes\"" .ReplaceLineEndings("\n")

let expected_binary_content = expected_content |> System.Text.Encoding.UTF8.GetBytes

"fixtures/test_validation_package_all_fields.fsx"
|> File.ReadAllBytes

module ValidationPackage =

open System.IO

let allFields = AVPRClient.ValidationPackage(
Name = "name",
Expand All @@ -114,7 +128,7 @@ module ValidationPackage =
MajorVersion = 1,
MinorVersion = 0,
PatchVersion = 0,
PackageContent = expected_content,
PackageContent = BinaryContent.expected_binary_content,
ReleaseDate = date,
Authors = [|Author.allFieldsClient|],
Tags = [|OntologyAnnotation.allFieldsClient|],
Expand Down
10 changes: 6 additions & 4 deletions tests/ClientTests/TypeExtensionsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@ module ValidationPackageIndex =
repoPath = "fixtures/test_validation_package_all_fields.fsx",
fileName = "test_validation_package_all_fields.fsx",
lastUpdated = ReferenceObjects.date,
contentHash = ReferenceObjects.PackageContentHash.expected_hash,
contentHash = ReferenceObjects.Hash.expected_hash,
metadata = ReferenceObjects.ValidationPackageMetadata.allFields
)

[<Fact>]
let ``toValidationpackage with release date`` () =
let ``toValidationPackage with release date`` () =
let actual = test_validation_package_all_fields.toValidationPackage(ReferenceObjects.date)
Assert.Equivalent(actual, ReferenceObjects.ValidationPackage.allFields)



[<Fact>]
let ``toPackageContentHash without direct file hash`` () =
let actual = test_validation_package_all_fields.toPackageContentHash()
Assert.Equivalent(ReferenceObjects.PackageContentHash.allFields, actual)
Assert.Equivalent(ReferenceObjects.Hash.allFields, actual)

[<Fact>]
let ``toPackageContentHash with direct file hash`` () =
let actual = test_validation_package_all_fields.toPackageContentHash(HashFileDirectly = true)
Assert.Equivalent(ReferenceObjects.PackageContentHash.allFields, actual)
Assert.Equivalent(ReferenceObjects.Hash.allFields, actual)

module Author =

Expand Down

0 comments on commit b5c40ee

Please sign in to comment.