From a4ba1ab07f73576936d539feb835491ee7d9ddcd Mon Sep 17 00:00:00 2001 From: Simon Avery Date: Sun, 28 Jan 2024 22:57:14 -0800 Subject: [PATCH] Improves testing of ComputePackageVerificationCode() and ComputeFileChecksum() --- test/runtests.jl | 1 + test/test_checksums.jl | 9 ++++++++- test/test_package/dir_link | 1 + test/test_package/file1.txt | 1 + test/test_package/file2.txt | 1 + test/test_package/file_link | 1 + test/test_package/src/bad_link | 1 + test/test_package/src/file3.txt | 1 + 8 files changed, 15 insertions(+), 1 deletion(-) create mode 120000 test/test_package/dir_link create mode 100644 test/test_package/file1.txt create mode 100644 test/test_package/file2.txt create mode 120000 test/test_package/file_link create mode 120000 test/test_package/src/bad_link create mode 100644 test/test_package/src/file3.txt diff --git a/test/runtests.jl b/test/runtests.jl index f251fed..785db18 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,6 +5,7 @@ using Test using JSON using Dates using TimeZones +using SHA @testset "Bool check" begin @test Bool(" True ") diff --git a/test/test_checksums.jl b/test/test_checksums.jl index 46593f6..927aa3e 100644 --- a/test/test_checksums.jl +++ b/test/test_checksums.jl @@ -1,7 +1,14 @@ @testset "checksums" begin verifcode= ComputePackageVerificationCode(pkgdir(SPDX), String["SPDX.spdx.json"], String[".git"]) @test verifcode isa SpdxPkgVerificationCodeV2 # No good way to indepently verify that the calculation is correct. + @test issubset(["SPDX.spdx.json"], verifcode.ExcludedFiles) checksum= ComputeFileChecksum("SHA256", joinpath(pkgdir(SPDX), "Project.toml")) - @test checksum isa SpdxChecksumV2 # No good way to indepently verify that the calculation is correct. + @test checksum isa SpdxChecksumV2 + @test checksum.Hash == open(joinpath(pkgdir(SPDX), "Project.toml")) do f + return bytes2hex(sha256(f)) + end + + linktest_code= ComputePackageVerificationCode(joinpath(pkgdir(SPDX), "test", "test_package")) + @test issetequal(linktest_code.ExcludedFiles, ["dir_link", "file_link", "src/bad_link"]) end \ No newline at end of file diff --git a/test/test_package/dir_link b/test/test_package/dir_link new file mode 120000 index 0000000..e831038 --- /dev/null +++ b/test/test_package/dir_link @@ -0,0 +1 @@ +src \ No newline at end of file diff --git a/test/test_package/file1.txt b/test/test_package/file1.txt new file mode 100644 index 0000000..4dd1ef7 --- /dev/null +++ b/test/test_package/file1.txt @@ -0,0 +1 @@ +This is a file. diff --git a/test/test_package/file2.txt b/test/test_package/file2.txt new file mode 100644 index 0000000..35eaca1 --- /dev/null +++ b/test/test_package/file2.txt @@ -0,0 +1 @@ +This is also a file diff --git a/test/test_package/file_link b/test/test_package/file_link new file mode 120000 index 0000000..c3ee11c --- /dev/null +++ b/test/test_package/file_link @@ -0,0 +1 @@ +file2.txt \ No newline at end of file diff --git a/test/test_package/src/bad_link b/test/test_package/src/bad_link new file mode 120000 index 0000000..b93736b --- /dev/null +++ b/test/test_package/src/bad_link @@ -0,0 +1 @@ +../temp.txt \ No newline at end of file diff --git a/test/test_package/src/file3.txt b/test/test_package/src/file3.txt new file mode 100644 index 0000000..050a3a6 --- /dev/null +++ b/test/test_package/src/file3.txt @@ -0,0 +1 @@ +This is a file as well.