From 098d98071d6628e8de750531f48e61110ff8f12a Mon Sep 17 00:00:00 2001 From: Zhijie Yang Date: Tue, 3 Dec 2024 13:11:30 +0100 Subject: [PATCH] test(manifest): restore basic and add basic hard link --- internal/manifest/manifest_test.go | 131 +++++++++++++++++++++++------ 1 file changed, 107 insertions(+), 24 deletions(-) diff --git a/internal/manifest/manifest_test.go b/internal/manifest/manifest_test.go index fea54728..72fc1e83 100644 --- a/internal/manifest/manifest_test.go +++ b/internal/manifest/manifest_test.go @@ -303,16 +303,6 @@ var generateManifestTests = []struct { Size: 1234, Slices: map[*setup.Slice]bool{slice1: true}, FinalSHA256: "final-hash", - HardLinkID: 1, - }, - "/hardlink": { - Path: "/hardlink", - Mode: 0456, - SHA256: "hash", - Size: 1234, - Slices: map[*setup.Slice]bool{slice1: true}, - FinalSHA256: "final-hash", - HardLinkID: 1, }, "/link": { Path: "/link", @@ -342,16 +332,6 @@ var generateManifestTests = []struct { Size: 1234, SHA256: "hash", FinalSHA256: "final-hash", - HardLinkID: 1, - }, { - Kind: "path", - Path: "/hardlink", - Mode: "0456", - Slices: []string{"package1_slice1"}, - Size: 1234, - SHA256: "hash", - FinalSHA256: "final-hash", - HardLinkID: 1, }, { Kind: "path", Path: "/link", @@ -383,10 +363,6 @@ var generateManifestTests = []struct { Kind: "content", Slice: "package1_slice1", Path: "/file", - }, { - Kind: "content", - Slice: "package1_slice1", - Path: "/hardlink", }, { Kind: "content", Slice: "package1_slice1", @@ -571,6 +547,113 @@ var generateManifestTests = []struct { }, }, error: `internal error: invalid manifest: path "/dir" has invalid options: size set for directory`, +}, { + summary: "Basic hard link", + selection: []*setup.Slice{slice1, slice2}, + report: &manifest.Report{ + Root: "/", + Entries: map[string]manifest.ReportEntry{ + "/file": { + Path: "/file", + Mode: 0456, + SHA256: "hash", + Size: 1234, + Slices: map[*setup.Slice]bool{slice1: true}, + FinalSHA256: "final-hash", + HardLinkID: 1, + }, + "/hardlink": { + Path: "/hardlink", + Mode: 0456, + SHA256: "hash", + Size: 1234, + Slices: map[*setup.Slice]bool{slice1: true}, + FinalSHA256: "final-hash", + HardLinkID: 1, + }, + "/link": { + Path: "/link", + Mode: 0567 | fs.ModeSymlink, + Link: "/target", + Slices: map[*setup.Slice]bool{slice1: true, slice2: true}, + }, + }, + }, + packageInfo: []*archive.PackageInfo{{ + Name: "package1", + Version: "v1", + Arch: "a1", + SHA256: "s1", + }, { + Name: "package2", + Version: "v2", + Arch: "a2", + SHA256: "s2", + }}, + expected: &manifestContents{ + Paths: []*manifest.Path{{ + Kind: "path", + Path: "/file", + Mode: "0456", + Slices: []string{"package1_slice1"}, + Size: 1234, + SHA256: "hash", + FinalSHA256: "final-hash", + HardLinkID: 1, + }, { + Kind: "path", + Path: "/hardlink", + Mode: "0456", + Slices: []string{"package1_slice1"}, + Size: 1234, + SHA256: "hash", + FinalSHA256: "final-hash", + HardLinkID: 1, + }, { + Kind: "path", + Path: "/link", + Link: "/target", + Mode: "0567", + Slices: []string{"package1_slice1", "package2_slice2"}, + }}, + Packages: []*manifest.Package{{ + Kind: "package", + Name: "package1", + Version: "v1", + Digest: "s1", + Arch: "a1", + }, { + Kind: "package", + Name: "package2", + Version: "v2", + Digest: "s2", + Arch: "a2", + }}, + Slices: []*manifest.Slice{{ + Kind: "slice", + Name: "package1_slice1", + }, { + Kind: "slice", + Name: "package2_slice2", + }}, + Contents: []*manifest.Content{{ + Kind: "content", + Slice: "package1_slice1", + Path: "/file", + }, { + Kind: "content", + Slice: "package1_slice1", + Path: "/hardlink", + }, { + Kind: "content", + Slice: "package1_slice1", + Path: "/link", + }, { + Kind: "content", + Slice: "package2_slice2", + Path: "/link", + }}, + }, }, { summary: "Skipped hard link id", report: &manifest.Report{