Skip to content

Commit

Permalink
fix: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornplusplus committed Sep 19, 2024
1 parent 41a9777 commit 25e11ba
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 34 deletions.
26 changes: 0 additions & 26 deletions cmd/chisel/cmd_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,6 @@ var infoTests = []infoTest{{
- mypkg1_myslice1
- mypkg2_myslice
`,
}, {
summary: "All kinds of paths",
input: infoRelease,
query: []string{"mypkg3"},
stdout: `
package: mypkg3
archive: ubuntu
slices:
myslice:
essential:
- mypkg1_myslice1
- mypkg2_myslice
contents:
/dir/arch-specific*: {arch: [amd64, arm64, i386]}
/dir/copy: {copy: /dir/file}
/dir/glob*: {}
/dir/mutable: {text: TODO, mutable: true, arch: riscv64}
/dir/other-file: {}
/dir/sub-dir/: {make: true, mode: 0644}
/dir/symlink: {symlink: /dir/file}
/dir/unfolded: {copy: /dir/file, mode: 0644}
/dir/until: {until: mutate}
mutate: |
# Test multi-line string.
content.write("/dir/mutable", foo)
`,
}, {
summary: "Same slice appearing multiple times",
input: infoRelease,
Expand Down
9 changes: 4 additions & 5 deletions internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"regexp"
"slices"
"sort"
"strings"

"golang.org/x/crypto/openpgp/packet"
Expand Down Expand Up @@ -831,10 +830,12 @@ func pathInfoToYAML(pi *PathInfo) (*yamlPath, error) {
case CopyPath:
path.Copy = pi.Info
case TextPath:
path.Text = &pi.Info
text := pi.Info
path.Text = &text
case SymlinkPath:
path.Symlink = pi.Info
case GlobPath:
// Nothing more needs to be done for this type.
default:
return nil, fmt.Errorf("internal error: unrecognised PathInfo type: %s", pi.Kind)
}
Expand All @@ -851,10 +852,8 @@ func sliceToYAML(s *Slice) (*yamlSlice, error) {
for _, key := range s.Essential {
slice.Essential = append(slice.Essential, key.String())
}
sort.Strings(slice.Essential)
for path, info := range s.Contents {
pi := info
yamlPath, err := pathInfoToYAML(&pi)
yamlPath, err := pathInfoToYAML(&info)
if err != nil {
return nil, err
}
Expand Down
57 changes: 54 additions & 3 deletions internal/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1665,9 +1665,7 @@ func (s *S) TestPackageMarshalYAML(c *C) {
dir := c.MkDir()
// Write chisel.yaml.
fpath := filepath.Join(dir, "chisel.yaml")
err := os.MkdirAll(filepath.Dir(fpath), 0755)
c.Assert(err, IsNil)
err = os.WriteFile(fpath, testutil.Reindent(data), 0644)
err := os.WriteFile(fpath, testutil.Reindent(data), 0644)
c.Assert(err, IsNil)
// Write the packages YAML.
for _, pkg := range test.release.Packages {
Expand All @@ -1688,6 +1686,59 @@ func (s *S) TestPackageMarshalYAML(c *C) {
}
}

func (s *S) TestPackageYAMLFormat(c *C) {
var input = map[string]string{
"chisel.yaml": string(defaultChiselYaml),
"slices/mypkg1.yaml": `
package: mypkg1
archive: ubuntu
slices:
myslice1:
contents:
/dir/file: {}
`,
"slices/mypkg3.yaml": `
package: mypkg3
archive: ubuntu
slices:
myslice:
essential:
- mypkg1_myslice1
contents:
/dir/arch-specific*: {arch: [amd64, arm64, i386]}
/dir/copy: {copy: /dir/file}
/dir/glob*: {}
/dir/mutable: {text: TODO, mutable: true, arch: riscv64}
/dir/other-file: {}
/dir/sub-dir/: {make: true, mode: 0644}
/dir/symlink: {symlink: /dir/file}
/dir/until: {until: mutate}
mutate: |
# Test multi-line string.
content.write("/dir/mutable", foo)
`,
}

dir := c.MkDir()
for fname, data := range input {
fpath := filepath.Join(dir, fname)
err := os.MkdirAll(filepath.Dir(fpath), 0755)
c.Assert(err, IsNil)
err = os.WriteFile(fpath, testutil.Reindent(string(data)), 0644)
c.Assert(err, IsNil)
}

release, err := setup.ReadRelease(dir)
c.Assert(err, IsNil)

for _, pkg := range release.Packages {
data, err := yaml.Marshal(pkg)
c.Assert(err, IsNil)
expected := string(testutil.Reindent(input[pkg.Path]))
c.Assert(strings.TrimSpace(string(data)), Equals, strings.TrimSpace(expected))
}
}

var sliceKeyTests = []struct {
input string
expected setup.SliceKey
Expand Down

0 comments on commit 25e11ba

Please sign in to comment.