diff --git a/internal/manifest/log.go b/internal/manifestutil/log.go similarity index 98% rename from internal/manifest/log.go rename to internal/manifestutil/log.go index 7fe0f91c..19396d9d 100644 --- a/internal/manifest/log.go +++ b/internal/manifestutil/log.go @@ -1,4 +1,4 @@ -package manifest +package manifestutil import ( "fmt" diff --git a/internal/manifest/manifest.go b/internal/manifestutil/manifest.go similarity index 99% rename from internal/manifest/manifest.go rename to internal/manifestutil/manifest.go index 8a4ae0cc..93da92b4 100644 --- a/internal/manifest/manifest.go +++ b/internal/manifestutil/manifest.go @@ -1,4 +1,4 @@ -package manifest +package manifestutil import ( "fmt" diff --git a/internal/manifest/manifest_test.go b/internal/manifestutil/manifest_test.go similarity index 88% rename from internal/manifest/manifest_test.go rename to internal/manifestutil/manifest_test.go index c8403444..90653b8b 100644 --- a/internal/manifest/manifest_test.go +++ b/internal/manifestutil/manifest_test.go @@ -1,4 +1,4 @@ -package manifest_test +package manifestutil_test import ( "bytes" @@ -8,7 +8,7 @@ import ( . "gopkg.in/check.v1" "github.com/canonical/chisel/internal/archive" - imanifest "github.com/canonical/chisel/internal/manifest" + "github.com/canonical/chisel/internal/manifestutil" "github.com/canonical/chisel/internal/setup" "github.com/canonical/chisel/internal/testutil" "github.com/canonical/chisel/pkg/manifest" @@ -87,7 +87,7 @@ func (s *S) TestFindPaths(c *C) { for _, test := range findPathsTests { c.Logf("Summary: %s", test.summary) - manifestSlices := imanifest.FindPaths(test.slices) + manifestSlices := manifestutil.FindPaths(test.slices) slicesByName := map[string]*setup.Slice{} for _, slice := range test.slices { @@ -117,7 +117,7 @@ var slice2 = &setup.Slice{ var generateManifestTests = []struct { summary string - report *imanifest.Report + report *manifestutil.Report packageInfo []*archive.PackageInfo selection []*setup.Slice expected *testutil.ManifestContents @@ -125,9 +125,9 @@ var generateManifestTests = []struct { }{{ summary: "Basic", selection: []*setup.Slice{slice1, slice2}, - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/file": { Path: "/file", Mode: 0456, @@ -207,9 +207,9 @@ var generateManifestTests = []struct { }, }, { summary: "Missing slice", - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/file": { Path: "/file", Mode: 0456, @@ -224,9 +224,9 @@ var generateManifestTests = []struct { error: `internal error: invalid manifest: path "/file" refers to missing slice package1_slice1`, }, { summary: "Missing package", - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/file": { Path: "/file", Mode: 0456, @@ -241,9 +241,9 @@ var generateManifestTests = []struct { error: `internal error: invalid manifest: slice package1_slice1 refers to missing package "package1"`, }, { summary: "Invalid path: link set for regular file", - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/file": { Path: "/file", Mode: 0456, @@ -255,9 +255,9 @@ var generateManifestTests = []struct { error: `internal error: invalid manifest: path "/file" has invalid options: link set for regular file`, }, { summary: "Invalid path: slices is empty", - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/file": { Path: "/file", Mode: 0456, @@ -267,9 +267,9 @@ var generateManifestTests = []struct { error: `internal error: invalid manifest: path "/file" has invalid options: slices is empty`, }, { summary: "Invalid path: link set for symlink", - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/link": { Path: "/link", Mode: 0456 | fs.ModeSymlink, @@ -280,9 +280,9 @@ var generateManifestTests = []struct { error: `internal error: invalid manifest: path "/link" has invalid options: link not set for symlink`, }, { summary: "Invalid path: sha256 set for symlink", - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/link": { Path: "/link", Mode: 0456 | fs.ModeSymlink, @@ -295,9 +295,9 @@ var generateManifestTests = []struct { error: `internal error: invalid manifest: path "/link" has invalid options: sha256 set for symlink`, }, { summary: "Invalid path: final_sha256 set for symlink", - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/link": { Path: "/link", Mode: 0456 | fs.ModeSymlink, @@ -310,9 +310,9 @@ var generateManifestTests = []struct { error: `internal error: invalid manifest: path "/link" has invalid options: final_sha256 set for symlink`, }, { summary: "Invalid path: size set for symlink", - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/link": { Path: "/link", Mode: 0456 | fs.ModeSymlink, @@ -325,9 +325,9 @@ var generateManifestTests = []struct { error: `internal error: invalid manifest: path "/link" has invalid options: size set for symlink`, }, { summary: "Invalid path: link set for directory", - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/dir": { Path: "/dir", Mode: 0456 | fs.ModeDir, @@ -339,9 +339,9 @@ var generateManifestTests = []struct { error: `internal error: invalid manifest: path "/dir" has invalid options: link set for directory`, }, { summary: "Invalid path: sha256 set for directory", - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/dir": { Path: "/dir", Mode: 0456 | fs.ModeDir, @@ -353,9 +353,9 @@ var generateManifestTests = []struct { error: `internal error: invalid manifest: path "/dir" has invalid options: sha256 set for directory`, }, { summary: "Invalid path: final_sha256 set for directory", - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/dir": { Path: "/dir", Mode: 0456 | fs.ModeDir, @@ -367,9 +367,9 @@ var generateManifestTests = []struct { error: `internal error: invalid manifest: path "/dir" has invalid options: final_sha256 set for directory`, }, { summary: "Invalid path: size set for directory", - report: &imanifest.Report{ + report: &manifestutil.Report{ Root: "/", - Entries: map[string]imanifest.ReportEntry{ + Entries: map[string]manifestutil.ReportEntry{ "/dir": { Path: "/dir", Mode: 0456 | fs.ModeDir, @@ -428,13 +428,13 @@ func (s *S) TestGenerateManifests(c *C) { }} } - options := &imanifest.WriteOptions{ + options := &manifestutil.WriteOptions{ PackageInfo: test.packageInfo, Selection: test.selection, Report: test.report, } var buffer bytes.Buffer - err := imanifest.Write(options, &buffer) + err := manifestutil.Write(options, &buffer) if test.error != "" { c.Assert(err, ErrorMatches, test.error) continue @@ -450,13 +450,13 @@ func (s *S) TestGenerateManifests(c *C) { } func (s *S) TestGenerateNoManifests(c *C) { - report, err := imanifest.NewReport("/") + report, err := manifestutil.NewReport("/") c.Assert(err, IsNil) - options := &imanifest.WriteOptions{ + options := &manifestutil.WriteOptions{ Report: report, } var buffer bytes.Buffer - err = imanifest.Write(options, &buffer) + err = manifestutil.Write(options, &buffer) c.Assert(err, IsNil) var reader io.Reader = &buffer diff --git a/internal/manifest/report.go b/internal/manifestutil/report.go similarity index 99% rename from internal/manifest/report.go rename to internal/manifestutil/report.go index 092ed823..c7762ea3 100644 --- a/internal/manifest/report.go +++ b/internal/manifestutil/report.go @@ -1,4 +1,4 @@ -package manifest +package manifestutil import ( "fmt" diff --git a/internal/manifest/report_test.go b/internal/manifestutil/report_test.go similarity index 91% rename from internal/manifest/report_test.go rename to internal/manifestutil/report_test.go index 9c001509..1576a377 100644 --- a/internal/manifest/report_test.go +++ b/internal/manifestutil/report_test.go @@ -1,4 +1,4 @@ -package manifest_test +package manifestutil_test import ( "io/fs" @@ -6,7 +6,7 @@ import ( . "gopkg.in/check.v1" "github.com/canonical/chisel/internal/fsutil" - "github.com/canonical/chisel/internal/manifest" + "github.com/canonical/chisel/internal/manifestutil" "github.com/canonical/chisel/internal/setup" ) @@ -64,13 +64,13 @@ var reportTests = []struct { add []sliceAndEntry mutate []*fsutil.Entry // indexed by path. - expected map[string]manifest.ReportEntry + expected map[string]manifestutil.ReportEntry // error after adding the last [sliceAndEntry]. err string }{{ summary: "Regular directory", add: []sliceAndEntry{{entry: sampleDir, slice: oneSlice}}, - expected: map[string]manifest.ReportEntry{ + expected: map[string]manifestutil.ReportEntry{ "/example-dir/": { Path: "/example-dir/", Mode: fs.ModeDir | 0654, @@ -83,7 +83,7 @@ var reportTests = []struct { {entry: sampleDir, slice: oneSlice}, {entry: sampleDir, slice: otherSlice}, }, - expected: map[string]manifest.ReportEntry{ + expected: map[string]manifestutil.ReportEntry{ "/example-dir/": { Path: "/example-dir/", Mode: fs.ModeDir | 0654, @@ -93,7 +93,7 @@ var reportTests = []struct { }, { summary: "Regular file", add: []sliceAndEntry{{entry: sampleFile, slice: oneSlice}}, - expected: map[string]manifest.ReportEntry{ + expected: map[string]manifestutil.ReportEntry{ "/example-file": { Path: "/example-file", Mode: 0777, @@ -105,7 +105,7 @@ var reportTests = []struct { }, { summary: "Regular file link", add: []sliceAndEntry{{entry: sampleLink, slice: oneSlice}}, - expected: map[string]manifest.ReportEntry{ + expected: map[string]manifestutil.ReportEntry{ "/example-link": { Path: "/example-link", Mode: 0777, @@ -120,7 +120,7 @@ var reportTests = []struct { {entry: sampleDir, slice: oneSlice}, {entry: sampleFile, slice: otherSlice}, }, - expected: map[string]manifest.ReportEntry{ + expected: map[string]manifestutil.ReportEntry{ "/example-dir/": { Path: "/example-dir/", Mode: fs.ModeDir | 0654, @@ -141,7 +141,7 @@ var reportTests = []struct { {entry: sampleFile, slice: oneSlice}, {entry: sampleFile, slice: oneSlice}, }, - expected: map[string]manifest.ReportEntry{ + expected: map[string]manifestutil.ReportEntry{ "/example-file": { Path: "/example-file", Mode: 0777, @@ -225,7 +225,7 @@ var reportTests = []struct { {entry: sampleDir, slice: oneSlice}, }, mutate: []*fsutil.Entry{&sampleFileMutated}, - expected: map[string]manifest.ReportEntry{ + expected: map[string]manifestutil.ReportEntry{ "/example-dir/": { Path: "/example-dir/", Mode: fs.ModeDir | 0654, @@ -247,7 +247,7 @@ var reportTests = []struct { {entry: sampleFile, slice: oneSlice}, }, mutate: []*fsutil.Entry{&sampleFile}, - expected: map[string]manifest.ReportEntry{ + expected: map[string]manifestutil.ReportEntry{ "/example-file": { Path: "/example-file", Mode: 0777, @@ -272,7 +272,7 @@ var reportTests = []struct { func (s *S) TestReport(c *C) { for _, test := range reportTests { var err error - report, err := manifest.NewReport("/base/") + report, err := manifestutil.NewReport("/base/") c.Assert(err, IsNil) for _, si := range test.add { err = report.Add(si.slice, &si.entry) @@ -290,12 +290,12 @@ func (s *S) TestReport(c *C) { } func (s *S) TestRootRelativePath(c *C) { - _, err := manifest.NewReport("../base/") + _, err := manifestutil.NewReport("../base/") c.Assert(err, ErrorMatches, `cannot use relative path for report root: "../base/"`) } func (s *S) TestRootOnlySlash(c *C) { - report, err := manifest.NewReport("/") + report, err := manifestutil.NewReport("/") c.Assert(err, IsNil) c.Assert(report.Root, Equals, "/") } diff --git a/internal/manifest/suite_test.go b/internal/manifestutil/suite_test.go similarity index 50% rename from internal/manifest/suite_test.go rename to internal/manifestutil/suite_test.go index 757a68af..b0df3185 100644 --- a/internal/manifest/suite_test.go +++ b/internal/manifestutil/suite_test.go @@ -1,11 +1,11 @@ -package manifest_test +package manifestutil_test import ( "testing" . "gopkg.in/check.v1" - "github.com/canonical/chisel/internal/manifest" + "github.com/canonical/chisel/internal/manifestutil" ) func Test(t *testing.T) { TestingT(t) } @@ -15,11 +15,11 @@ type S struct{} var _ = Suite(&S{}) func (s *S) SetUpTest(c *C) { - manifest.SetDebug(true) - manifest.SetLogger(c) + manifestutil.SetDebug(true) + manifestutil.SetLogger(c) } func (s *S) TearDownTest(c *C) { - manifest.SetDebug(false) - manifest.SetLogger(nil) + manifestutil.SetDebug(false) + manifestutil.SetLogger(nil) } diff --git a/internal/slicer/slicer.go b/internal/slicer/slicer.go index 2d4c45e4..9d4fc1e6 100644 --- a/internal/slicer/slicer.go +++ b/internal/slicer/slicer.go @@ -18,7 +18,7 @@ import ( "github.com/canonical/chisel/internal/archive" "github.com/canonical/chisel/internal/deb" "github.com/canonical/chisel/internal/fsutil" - "github.com/canonical/chisel/internal/manifest" + "github.com/canonical/chisel/internal/manifestutil" "github.com/canonical/chisel/internal/scripts" "github.com/canonical/chisel/internal/setup" ) @@ -153,7 +153,7 @@ func Run(options *RunOptions) error { // listed as until: mutate in all the slices that reference them. knownPaths := map[string]pathData{} addKnownPath(knownPaths, "/", pathData{}) - report, err := manifest.NewReport(targetDir) + report, err := manifestutil.NewReport(targetDir) if err != nil { return fmt.Errorf("internal error: cannot create report: %w", err) } @@ -317,8 +317,8 @@ func Run(options *RunOptions) error { } func generateManifests(targetDir string, selection *setup.Selection, - report *manifest.Report, pkgInfos []*archive.PackageInfo) error { - manifestSlices := manifest.FindPaths(selection.Slices) + report *manifestutil.Report, pkgInfos []*archive.PackageInfo) error { + manifestSlices := manifestutil.FindPaths(selection.Slices) if len(manifestSlices) == 0 { // Nothing to do. return nil @@ -350,12 +350,12 @@ func generateManifests(targetDir string, selection *setup.Selection, return err } defer w.Close() - writeOptions := &manifest.WriteOptions{ + writeOptions := &manifestutil.WriteOptions{ PackageInfo: pkgInfos, Selection: selection.Slices, Report: report, } - err = manifest.Write(writeOptions, w) + err = manifestutil.Write(writeOptions, w) return err }