From 39ba448d851afe6f3191afda6bdbb1f62575e81a Mon Sep 17 00:00:00 2001 From: Alberto Carretero Date: Mon, 1 Apr 2024 12:31:44 +0200 Subject: [PATCH] refactor: filter created entries for report (#124) To make the content transparent and facilitate changing the package, this commit creates the deb used for testing programmatically instead of embedding it as a base64-encoded blob directly. Also, the entries not mentioned explicitly in the slice definition will not be added to the report (e.g. copyright, parent directories). Additionally, we have removed the Globbed option and simplified it. --- internal/deb/extract.go | 21 +-- internal/deb/extract_test.go | 20 +-- internal/fsutil/create.go | 4 +- internal/slicer/report.go | 5 +- internal/slicer/report_test.go | 26 +++- internal/slicer/slicer.go | 28 ++-- internal/slicer/slicer_test.go | 256 ++++++++++++++++++++++++++------- internal/testutil/pkgdata.go | 16 +-- 8 files changed, 274 insertions(+), 102 deletions(-) diff --git a/internal/deb/extract.go b/internal/deb/extract.go index 8ac6efdf..9fa3f778 100644 --- a/internal/deb/extract.go +++ b/internal/deb/extract.go @@ -24,8 +24,10 @@ type ExtractOptions struct { Package string TargetDir string Extract map[string][]ExtractInfo - Globbed map[string][]string - Create func(options *fsutil.CreateOptions) error + // Create can optionally be set to control the creation of extracted entries. + // extractInfo is set to the matching entry in Extract, and is nil in cases where + // the created entry is implicit and unlisted (for example, parent directories). + Create func(extractInfo *ExtractInfo, options *fsutil.CreateOptions) error } type ExtractInfo struct { @@ -46,7 +48,7 @@ func getValidOptions(options *ExtractOptions) (*ExtractOptions, error) { if options.Create == nil { validOpts := *options - validOpts.Create = func(o *fsutil.CreateOptions) error { + validOpts.Create = func(_ *ExtractInfo, o *fsutil.CreateOptions) error { _, err := fsutil.Create(o) return err } @@ -185,9 +187,6 @@ func extractData(dataReader io.Reader, options *ExtractOptions) error { if globPath != "" { extractInfos = options.Extract[globPath] delete(pendingPaths, globPath) - if options.Globbed != nil { - options.Globbed[globPath] = append(options.Globbed[globPath], sourcePath) - } } else { extractInfos, ok = options.Extract[sourcePath] if ok { @@ -196,11 +195,12 @@ func extractData(dataReader io.Reader, options *ExtractOptions) error { // Base directory for extracted content. Relevant mainly to preserve // the metadata, since the extracted content itself will also create // any missing directories unaccounted for in the options. - err := options.Create(&fsutil.CreateOptions{ + createOptions := &fsutil.CreateOptions{ Path: filepath.Join(options.TargetDir, sourcePath), Mode: tarHeader.FileInfo().Mode(), MakeParents: true, - }) + } + err := options.Create(nil, createOptions) if err != nil { return err } @@ -237,13 +237,14 @@ func extractData(dataReader io.Reader, options *ExtractOptions) error { if extractInfo.Mode != 0 { tarHeader.Mode = int64(extractInfo.Mode) } - err := options.Create(&fsutil.CreateOptions{ + createOptions := &fsutil.CreateOptions{ Path: targetPath, Mode: tarHeader.FileInfo().Mode(), Data: pathReader, Link: tarHeader.Linkname, MakeParents: true, - }) + } + err := options.Create(&extractInfo, createOptions) if err != nil { return err } diff --git a/internal/deb/extract_test.go b/internal/deb/extract_test.go index 3cd09044..c3297b4b 100644 --- a/internal/deb/extract_test.go +++ b/internal/deb/extract_test.go @@ -2,7 +2,6 @@ package deb_test import ( "bytes" - "io/fs" "path/filepath" "sort" "strings" @@ -19,7 +18,6 @@ type extractTest struct { pkgdata []byte options deb.ExtractOptions hackopt func(o *deb.ExtractOptions) - globbed map[string][]string result map[string]string // paths which the extractor did not create explicitly. notCreated []string @@ -179,7 +177,7 @@ var extractTests = []extractTest{{ }, notCreated: []string{"/dir/"}, }, { - summary: "Globbing with reporting of globbed paths", + summary: "Globbing multiple paths", pkgdata: testutil.PackageData["test-package"], options: deb.ExtractOptions{ Extract: map[string][]deb.ExtractInfo{ @@ -199,10 +197,6 @@ var extractTests = []extractTest{{ "/dir/several/levels/deep/": "dir 0755", "/dir/several/levels/deep/file": "file 0644 6bc26dff", }, - globbed: map[string][]string{ - "/dir/n*/": []string{"/dir/nested/"}, - "/dir/s**": []string{"/dir/several/", "/dir/several/levels/", "/dir/several/levels/deep/", "/dir/several/levels/deep/file"}, - }, notCreated: []string{"/dir/"}, }, { summary: "Globbing must have matching source and target", @@ -336,9 +330,9 @@ func (s *S) TestExtract(c *C) { options.Package = "test-package" options.TargetDir = dir createdPaths := make(map[string]bool) - options.Create = func(o *fsutil.CreateOptions) error { + options.Create = func(_ *deb.ExtractInfo, o *fsutil.CreateOptions) error { relPath := filepath.Clean("/" + strings.TrimPrefix(o.Path, dir)) - if o.Mode&fs.ModeDir != 0 { + if o.Mode.IsDir() { relPath = relPath + "/" } createdPaths[relPath] = true @@ -350,10 +344,6 @@ func (s *S) TestExtract(c *C) { test.hackopt(&options) } - if test.globbed != nil { - options.Globbed = make(map[string][]string) - } - err := deb.Extract(bytes.NewBuffer(test.pkgdata), &options) if test.error != "" { c.Assert(err, ErrorMatches, test.error) @@ -362,10 +352,6 @@ func (s *S) TestExtract(c *C) { c.Assert(err, IsNil) } - if test.globbed != nil { - c.Assert(options.Globbed, DeepEquals, test.globbed) - } - if test.notCreated != nil { notCreated := []string{} for path := range test.result { diff --git a/internal/fsutil/create.go b/internal/fsutil/create.go index f72830ee..2249f3a8 100644 --- a/internal/fsutil/create.go +++ b/internal/fsutil/create.go @@ -39,6 +39,7 @@ func Create(options *CreateOptions) (*Entry, error) { o := &optsCopy var err error + var hash string if o.MakeParents { if err := os.MkdirAll(filepath.Dir(o.Path), 0755); err != nil { return nil, err @@ -47,6 +48,7 @@ func Create(options *CreateOptions) (*Entry, error) { switch o.Mode & fs.ModeType { case 0: err = createFile(o) + hash = hex.EncodeToString(rp.h.Sum(nil)) case fs.ModeDir: err = createDir(o) case fs.ModeSymlink: @@ -61,7 +63,7 @@ func Create(options *CreateOptions) (*Entry, error) { entry := &Entry{ Path: o.Path, Mode: o.Mode, - Hash: hex.EncodeToString(rp.h.Sum(nil)), + Hash: hash, Size: rp.size, Link: o.Link, } diff --git a/internal/slicer/report.go b/internal/slicer/report.go index 45b867f1..22600399 100644 --- a/internal/slicer/report.go +++ b/internal/slicer/report.go @@ -32,7 +32,7 @@ type Report struct { // provided root path. func NewReport(root string) *Report { return &Report{ - Root: root, + Root: filepath.Clean(root) + "/", Entries: make(map[string]ReportEntry), } } @@ -42,6 +42,9 @@ func (r *Report) Add(slice *setup.Slice, fsEntry *fsutil.Entry) error { return fmt.Errorf("cannot add path %q outside of root %q", fsEntry.Path, r.Root) } relPath := filepath.Clean("/" + strings.TrimPrefix(fsEntry.Path, r.Root)) + if fsEntry.Mode.IsDir() { + relPath = relPath + "/" + } if entry, ok := r.Entries[relPath]; ok { if fsEntry.Mode != entry.Mode { diff --git a/internal/slicer/report_test.go b/internal/slicer/report_test.go index 5185fd28..0b04f70e 100644 --- a/internal/slicer/report_test.go +++ b/internal/slicer/report_test.go @@ -27,7 +27,7 @@ var otherSlice = &setup.Slice{ } var sampleDir = fsutil.Entry{ - Path: "/base/exampleDir", + Path: "/base/exampleDir/", Mode: fs.ModeDir | 0654, Link: "", } @@ -64,8 +64,8 @@ var reportTests = []struct { summary: "Regular directory", add: []sliceAndEntry{{entry: sampleDir, slice: oneSlice}}, expected: map[string]slicer.ReportEntry{ - "/exampleDir": { - Path: "/exampleDir", + "/exampleDir/": { + Path: "/exampleDir/", Mode: fs.ModeDir | 0654, Slices: map[*setup.Slice]bool{oneSlice: true}, Link: "", @@ -77,8 +77,8 @@ var reportTests = []struct { {entry: sampleDir, slice: otherSlice}, }, expected: map[string]slicer.ReportEntry{ - "/exampleDir": { - Path: "/exampleDir", + "/exampleDir/": { + Path: "/exampleDir/", Mode: fs.ModeDir | 0654, Slices: map[*setup.Slice]bool{oneSlice: true, otherSlice: true}, Link: "", @@ -114,8 +114,8 @@ var reportTests = []struct { {entry: sampleFile, slice: otherSlice}, }, expected: map[string]slicer.ReportEntry{ - "/exampleDir": { - Path: "/exampleDir", + "/exampleDir/": { + Path: "/exampleDir/", Mode: fs.ModeDir | 0654, Slices: map[*setup.Slice]bool{oneSlice: true}, Link: "", @@ -195,6 +195,18 @@ var reportTests = []struct { }, slice: oneSlice}, }, err: `path "/exampleFile" reported twice with diverging link: "distinct link" != ""`, +}, { + summary: "Error for path outside root", + add: []sliceAndEntry{ + {entry: fsutil.Entry{Path: "/file"}, slice: oneSlice}, + }, + err: `cannot add path "/file" outside of root "/base/"`, +}, { + summary: "File name has root prefix but without the directory slash", + add: []sliceAndEntry{ + {entry: fsutil.Entry{Path: "/basefile"}, slice: oneSlice}, + }, + err: `cannot add path "/basefile" outside of root "/base/"`, }} func (s *S) TestReportAdd(c *C) { diff --git a/internal/slicer/slicer.go b/internal/slicer/slicer.go index 22c0f65a..a7dd4520 100644 --- a/internal/slicer/slicer.go +++ b/internal/slicer/slicer.go @@ -158,13 +158,31 @@ func Run(options *RunOptions) (*Report, error) { Package: slice.Package, Extract: extract[slice.Package], TargetDir: targetDir, - Globbed: globbedPaths, // Creates the filesystem entry and adds it to the report. - Create: func(o *fsutil.CreateOptions) error { + Create: func(extractInfo *deb.ExtractInfo, o *fsutil.CreateOptions) error { entry, err := fsutil.Create(o) if err != nil { return err } + + // We only want to keep the entries that were explicitly listed + // in the slice definition. + if extractInfo == nil { + return nil + } + if _, ok := slice.Contents[extractInfo.Path]; !ok { + return nil + } + + // Check whether the file was created because it matched a glob. + if strings.ContainsAny(extractInfo.Path, "*?") { + relPath := filepath.Clean("/" + strings.TrimLeft(o.Path, targetDir)) + if o.Mode.IsDir() { + relPath = relPath + "/" + } + globbedPaths[extractInfo.Path] = append(globbedPaths[extractInfo.Path], relPath) + addKnownPath(relPath) + } return report.Add(slice, entry) }, }) @@ -175,12 +193,6 @@ func Run(options *RunOptions) (*Report, error) { } } - for _, expandedPaths := range globbedPaths { - for _, path := range expandedPaths { - addKnownPath(path) - } - } - // Create new content not coming from packages. done := make(map[string]bool) for _, slice := range options.Selection.Slices { diff --git a/internal/slicer/slicer_test.go b/internal/slicer/slicer_test.go index f1ca6fed..91067d1e 100644 --- a/internal/slicer/slicer_test.go +++ b/internal/slicer/slicer_test.go @@ -26,6 +26,7 @@ type slicerTest struct { summary string arch string release map[string]string + pkgs map[string][]byte slices []setup.SliceKey hackopt func(c *C, opts *slicer.RunOptions) filesystem map[string]string @@ -65,14 +66,13 @@ var packageEntries = map[string][]testutil.TarEntry{ }, } -// Hardcoded copyright files from test-package package that will be automatically -// injected into every slice. -var copyrightEntries = map[string]string{ - "/usr/": "dir 0755", - "/usr/share/": "dir 0755", - "/usr/share/doc/": "dir 0755", - "/usr/share/doc/test-package/": "dir 0755", - "/usr/share/doc/test-package/copyright": "file 0644 c2fca2aa", +var testPackageCopyrightEntries = []testutil.TarEntry{ + // Hardcoded copyright paths. + testutil.Dir(0755, "./usr/"), + testutil.Dir(0755, "./usr/share/"), + testutil.Dir(0755, "./usr/share/doc/"), + testutil.Dir(0755, "./usr/share/doc/test-package/"), + testutil.Reg(0644, "./usr/share/doc/test-package/copyright", "copyright"), } var slicerTests = []slicerTest{{ @@ -102,12 +102,10 @@ var slicerTests = []slicerTest{{ "/other-dir/file": "symlink ../dir/file", }, report: map[string]string{ - "/dir/": "dir 0755 {test-package_myslice}", "/dir/file": "file 0644 cc55e2ec {test-package_myslice}", "/dir/file-copy": "file 0644 cc55e2ec {test-package_myslice}", "/dir/foo/bar/": "dir 01777 {test-package_myslice}", "/dir/text-file": "file 0644 5b41362b {test-package_myslice}", - "/other-dir/": "dir 0755 {test-package_myslice}", "/other-dir/file": "symlink ../dir/file {test-package_myslice}", }, }, { @@ -150,7 +148,6 @@ var slicerTests = []slicerTest{{ "/parent/new": "file 0644 5b41362b", }, report: map[string]string{ - "/parent/": "dir 01777 {test-package_myslice}", "/parent/new": "file 0644 5b41362b {test-package_myslice}", }, }, { @@ -172,8 +169,6 @@ var slicerTests = []slicerTest{{ "/parent/permissions/new": "file 0644 5b41362b", }, report: map[string]string{ - "/parent/": "dir 01777 {test-package_myslice}", - "/parent/permissions/": "dir 0764 {test-package_myslice}", "/parent/permissions/new": "file 0644 5b41362b {test-package_myslice}", }, }, { @@ -194,7 +189,6 @@ var slicerTests = []slicerTest{{ "/parent/new/": "dir 0755", }, report: map[string]string{ - "/parent/": "dir 01777 {test-package_myslice}", "/parent/new/": "dir 0755 {test-package_myslice}", }, }, { @@ -224,13 +218,192 @@ var slicerTests = []slicerTest{{ "/dir/nested/copy-3": "file 0644 84237a05", }, report: map[string]string{ - "/dir/": "dir 0755 {test-package_myslice}", - "/dir/nested/": "dir 0755 {test-package_myslice}", "/dir/nested/copy-1": "file 0644 84237a05 {test-package_myslice}", "/dir/nested/copy-3": "file 0644 84237a05 {test-package_myslice}", "/dir/text-file-1": "file 0644 5b41362b {test-package_myslice}", "/dir/text-file-3": "file 0644 5b41362b {test-package_myslice}", }, +}, { + summary: "Copyright is installed", + slices: []setup.SliceKey{{"test-package", "myslice"}}, + pkgs: map[string][]byte{ + // Add the copyright entries to the package. + "test-package": testutil.MustMakeDeb(append(testutil.TestPackageEntries, testPackageCopyrightEntries...)), + }, + release: map[string]string{ + "slices/mydir/test-package.yaml": ` + package: test-package + slices: + myslice: + contents: + /dir/file: + `, + }, + filesystem: map[string]string{ + "/dir/": "dir 0755", + "/dir/file": "file 0644 cc55e2ec", + // Hardcoded copyright entries. + "/usr/": "dir 0755", + "/usr/share/": "dir 0755", + "/usr/share/doc/": "dir 0755", + "/usr/share/doc/test-package/": "dir 0755", + "/usr/share/doc/test-package/copyright": "file 0644 c2fca2aa", + }, + report: map[string]string{ + "/dir/file": "file 0644 cc55e2ec {test-package_myslice}", + }, +}, { + summary: "Install two packages", + slices: []setup.SliceKey{ + {"test-package", "myslice"}, + {"other-package", "myslice"}}, + pkgs: map[string][]byte{ + "test-package": testutil.PackageData["test-package"], + "other-package": testutil.PackageData["other-package"], + }, + release: map[string]string{ + "slices/mydir/test-package.yaml": ` + package: test-package + slices: + myslice: + contents: + /dir/file: + /foo/: {make: true} + `, + "slices/mydir/other-package.yaml": ` + package: other-package + slices: + myslice: + contents: + /file: + /bar/: {make: true} + `, + }, + filesystem: map[string]string{ + "/bar/": "dir 0755", + "/dir/": "dir 0755", + "/dir/file": "file 0644 cc55e2ec", + "/file": "file 0644 fc02ca0e", + "/foo/": "dir 0755", + }, + report: map[string]string{ + "/foo/": "dir 0755 {test-package_myslice}", + "/dir/file": "file 0644 cc55e2ec {test-package_myslice}", + "/bar/": "dir 0755 {other-package_myslice}", + "/file": "file 0644 fc02ca0e {other-package_myslice}", + }, +}, { + summary: "Install two packages, explicit path has preference over implicit parent", + slices: []setup.SliceKey{ + {"implicit-parent", "myslice"}, + {"explicit-dir", "myslice"}}, + pkgs: map[string][]byte{ + "implicit-parent": testutil.MustMakeDeb([]testutil.TarEntry{ + testutil.Dir(0755, "./dir/"), + testutil.Reg(0644, "./dir/file", "random"), + }), + "explicit-dir": testutil.MustMakeDeb([]testutil.TarEntry{ + testutil.Dir(01777, "./dir/"), + }), + }, + release: map[string]string{ + "slices/mydir/implicit-parent.yaml": ` + package: implicit-parent + slices: + myslice: + contents: + /dir/file: + `, + "slices/mydir/explicit-dir.yaml": ` + package: explicit-dir + slices: + myslice: + contents: + /dir/: + `, + }, + filesystem: map[string]string{ + // TODO this is the wrong mode for the directory, it should be 01777. + "/dir/": "dir 0755", + "/dir/file": "file 0644 a441b15f", + }, + report: map[string]string{ + "/dir/": "dir 01777 {explicit-dir_myslice}", + "/dir/file": "file 0644 a441b15f {implicit-parent_myslice}", + }, +}, { + summary: "Install two packages, explicit path has preference over implicit parent (reverse order)", + slices: []setup.SliceKey{ + {"explicit-dir", "myslice"}, + {"implicit-parent", "myslice"}}, + pkgs: map[string][]byte{ + "implicit-parent": testutil.MustMakeDeb([]testutil.TarEntry{ + testutil.Dir(0755, "./dir/"), + testutil.Reg(0644, "./dir/file", "random"), + }), + "explicit-dir": testutil.MustMakeDeb([]testutil.TarEntry{ + testutil.Dir(01777, "./dir/"), + }), + }, + release: map[string]string{ + "slices/mydir/implicit-parent.yaml": ` + package: implicit-parent + slices: + myslice: + contents: + /dir/file: + `, + "slices/mydir/explicit-dir.yaml": ` + package: explicit-dir + slices: + myslice: + contents: + /dir/: + `, + }, + filesystem: map[string]string{ + // TODO this is the wrong mode for the directory, it should be 01777. + "/dir/": "dir 0755", + "/dir/file": "file 0644 a441b15f", + }, + report: map[string]string{ + "/dir/": "dir 01777 {explicit-dir_myslice}", + "/dir/file": "file 0644 a441b15f {implicit-parent_myslice}", + }, +}, { + summary: "Valid same file in two slices in different packages", + slices: []setup.SliceKey{ + {"test-package", "myslice"}, + {"other-package", "myslice"}}, + pkgs: map[string][]byte{ + "test-package": testutil.PackageData["test-package"], + "other-package": testutil.PackageData["other-package"], + }, + release: map[string]string{ + "slices/mydir/test-package.yaml": ` + package: test-package + slices: + myslice: + contents: + /textFile: {text: SAME_TEXT} + `, + "slices/mydir/other-package.yaml": ` + package: other-package + slices: + myslice: + contents: + /textFile: {text: SAME_TEXT} + `, + }, + filesystem: map[string]string{ + "/textFile": "file 0644 c6c83d10", + }, + report: map[string]string{ + // Note: This is the only case where two slices can declare the same + // file without conflicts. + // TODO which slice(s) should own the file. + "/textFile": "file 0644 c6c83d10 {other-package_myslice}", + }, }, { summary: "Script: write a file", slices: []setup.SliceKey{{"test-package", "myslice"}}, @@ -250,7 +423,6 @@ var slicerTests = []slicerTest{{ "/dir/text-file": "file 0644 d98cf53e", }, report: map[string]string{ - "/dir/": "dir 0755 {test-package_myslice}", "/dir/text-file": "file 0644 5b41362b {test-package_myslice}", }, }, { @@ -276,7 +448,6 @@ var slicerTests = []slicerTest{{ "/foo/text-file-2": "file 0644 5b41362b", }, report: map[string]string{ - "/dir/": "dir 0755 {test-package_myslice}", "/dir/text-file-1": "file 0644 5b41362b {test-package_myslice}", "/foo/text-file-2": "file 0644 d98cf53e {test-package_myslice}", }, @@ -302,7 +473,7 @@ var slicerTests = []slicerTest{{ "/foo/text-file-2": "file 0644 5b41362b", }, report: map[string]string{ - "/dir/": "dir 0755 {test-package_myslice}", + // TODO this path needs to be removed from the report. "/dir/text-file-1": "file 0644 5b41362b {test-package_myslice}", "/foo/text-file-2": "file 0644 d98cf53e {test-package_myslice}", }, @@ -324,11 +495,12 @@ var slicerTests = []slicerTest{{ "/other-dir/": "dir 0755", }, report: map[string]string{ + // TODO These first three entries should be removed from the report. "/dir/nested/": "dir 0755 {test-package_myslice}", "/dir/nested/file": "file 0644 84237a05 {test-package_myslice}", "/dir/nested/other-file": "file 0644 6b86b273 {test-package_myslice}", - "/other-dir/": "dir 0755 {test-package_myslice}", - "/other-dir/text-file": "file 0644 5b41362b {test-package_myslice}", + + "/other-dir/text-file": "file 0644 5b41362b {test-package_myslice}", }, }, { summary: "Script: 'until' does not remove non-empty directories", @@ -349,7 +521,6 @@ var slicerTests = []slicerTest{{ "/dir/nested/file-copy": "file 0644 cc55e2ec", }, report: map[string]string{ - "/dir/": "dir 0755 {test-package_myslice}", "/dir/nested/": "dir 0755 {test-package_myslice}", "/dir/nested/file-copy": "file 0644 cc55e2ec {test-package_myslice}", }, @@ -500,6 +671,10 @@ var slicerTests = []slicerTest{{ }, { summary: "Duplicate copyright symlink is ignored", slices: []setup.SliceKey{{"copyright-symlink-openssl", "bins"}}, + pkgs: map[string][]byte{ + "copyright-symlink-openssl": testutil.MustMakeDeb(packageEntries["copyright-symlink-openssl"]), + "copyright-symlink-libssl3": testutil.MustMakeDeb(packageEntries["copyright-symlink-libssl3"]), + }, release: map[string]string{ "slices/mydir/copyright-symlink-libssl3.yaml": ` package: copyright-symlink-libssl3 @@ -592,8 +767,6 @@ var slicerTests = []slicerTest{{ "/dir/nested/file": "file 0644 84237a05", }, report: map[string]string{ - "/dir/": "dir 0755 {test-package_myslice}", - "/dir/nested/": "dir 0755 {test-package_myslice}", "/dir/nested/file": "file 0644 84237a05 {test-package_myslice}", }, }} @@ -661,6 +834,12 @@ func runSlicerTests(c *C, tests []slicerTest) { test.release["chisel.yaml"] = string(defaultChiselYaml) } + if test.pkgs == nil { + test.pkgs = map[string][]byte{ + "test-package": testutil.PackageData["test-package"], + } + } + releaseDir := c.MkDir() for path, data := range test.release { fpath := filepath.Join(releaseDir, path) @@ -676,14 +855,6 @@ func runSlicerTests(c *C, tests []slicerTest) { selection, err := setup.Select(release, test.slices) c.Assert(err, IsNil) - pkgs := map[string][]byte{ - "test-package": testutil.PackageData["test-package"], - } - for name, entries := range packageEntries { - deb, err := testutil.MakeDeb(entries) - c.Assert(err, IsNil) - pkgs[name] = deb - } archives := map[string]archive.Archive{} for name, setupArchive := range release.Archives { archive := &testArchive{ @@ -694,7 +865,7 @@ func runSlicerTests(c *C, tests []slicerTest) { Components: setupArchive.Components, Arch: test.arch, }, - pkgs: pkgs, + pkgs: test.pkgs, } archives[name] = archive } @@ -717,25 +888,11 @@ func runSlicerTests(c *C, tests []slicerTest) { } if test.filesystem != nil { - result := make(map[string]string, len(copyrightEntries)+len(test.filesystem)) - for k, v := range copyrightEntries { - result[k] = v - } - for k, v := range test.filesystem { - result[k] = v - } - c.Assert(testutil.TreeDump(targetDir), DeepEquals, result) + c.Assert(testutil.TreeDump(targetDir), DeepEquals, test.filesystem) } if test.report != nil { - result := make(map[string]string, len(copyrightEntries)+len(test.filesystem)) - for k, v := range copyrightEntries { - result[k] = v + " {test-package_myslice}" - } - for k, v := range test.report { - result[k] = v - } - c.Assert(treeDumpReport(report), DeepEquals, result) + c.Assert(treeDumpReport(report), DeepEquals, test.report) } } } @@ -752,7 +909,6 @@ func treeDumpReport(report *slicer.Report) map[string]string { var fsDump string switch entry.Mode.Type() { case fs.ModeDir: - entry.Path = entry.Path + "/" fsDump = fmt.Sprintf("dir %#o", fperm) case fs.ModeSymlink: fsDump = fmt.Sprintf("symlink %s", entry.Link) diff --git a/internal/testutil/pkgdata.go b/internal/testutil/pkgdata.go index 4142f785..11bc9028 100644 --- a/internal/testutil/pkgdata.go +++ b/internal/testutil/pkgdata.go @@ -12,7 +12,7 @@ import ( var PackageData = map[string][]byte{} -var testPackageEntries = []TarEntry{ +var TestPackageEntries = []TarEntry{ Dir(0755, "./"), Dir(0755, "./dir/"), Reg(0644, "./dir/file", "12u3q0wej ajsd"), @@ -28,16 +28,16 @@ var testPackageEntries = []TarEntry{ Dir(01777, "./parent/"), Dir(0764, "./parent/permissions/"), Reg(0755, "./parent/permissions/file", "ajse0"), - // Hardcoded copyright paths. - Dir(0755, "./usr/"), - Dir(0755, "./usr/share/"), - Dir(0755, "./usr/share/doc/"), - Dir(0755, "./usr/share/doc/test-package/"), - Reg(0644, "./usr/share/doc/test-package/copyright", "copyright"), +} + +var OtherPackageEntries = []TarEntry{ + Dir(0755, "./"), + Reg(0644, "./file", "masfdko"), } func init() { - PackageData["test-package"] = MustMakeDeb(testPackageEntries) + PackageData["test-package"] = MustMakeDeb(TestPackageEntries) + PackageData["other-package"] = MustMakeDeb(OtherPackageEntries) } type TarEntry struct {