Skip to content

Commit

Permalink
test mode of manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Aug 29, 2024
1 parent 391119e commit 154697b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 0 additions & 1 deletion internal/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func (manifest *Manifest) IterateContents(slice string, onMatch func(*Content) e
// load practically the whole manifest into memory and unmarshall all the
// entries.
func Validate(manifest *Manifest) (err error) {
// TODO validate entry of manifest path is correct.
defer func() {
if err != nil {
err = fmt.Errorf("invalid manifest: %s", err)
Expand Down
8 changes: 3 additions & 5 deletions internal/slicer/slicer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
"github.com/canonical/chisel/internal/setup"
)

const ManifestFileName = "manifest.wall"
const ManifestMode fs.FileMode = 0644

type RunOptions struct {
Selection *setup.Selection
Archives map[string]archive.Archive
Expand Down Expand Up @@ -573,11 +576,6 @@ func unixPerm(mode fs.FileMode) (perm uint32) {
return perm
}

const ManifestFileName = "manifest.wall"

// TODO change mode in one usage and see test failing.
const ManifestMode fs.FileMode = 0644

// locateManifestSlices finds the paths marked with "generate:manifest" and
// returns a map from the manifest path to all the slices that declare it.
func locateManifestSlices(slices []*setup.Slice) (map[string][]*setup.Slice, error) {
Expand Down
8 changes: 8 additions & 0 deletions internal/slicer/slicer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,9 @@ func runSlicerTests(c *C, tests []slicerTest) {
c.Assert(err, IsNil)

// Get the manifest from disk and read it.
s, err := os.Stat(path.Join(options.TargetDir, manifestPath))
c.Assert(err, IsNil)
c.Assert(s.Mode(), Equals, slicer.ManifestMode)
f, err := os.Open(path.Join(options.TargetDir, manifestPath))
defer f.Close()

Check failure on line 1285 in internal/slicer/slicer_test.go

View workflow job for this annotation

GitHub Actions / Lint

SA5001: should check returned error before deferring f.Close() (staticcheck)
c.Assert(err, IsNil)
Expand All @@ -1288,6 +1291,11 @@ func runSlicerTests(c *C, tests []slicerTest) {
c.Assert(err, IsNil)
err = manifest.Validate(mfest)
c.Assert(err, IsNil)
err = mfest.IteratePaths(manifestPath, func(p *manifest.Path) error {
c.Assert(p.Mode, Equals, fmt.Sprintf("%#o", slicer.ManifestMode))
return nil
})
c.Assert(err, IsNil)

// Assert state of final filesystem.
if test.filesystem != nil {
Expand Down

0 comments on commit 154697b

Please sign in to comment.