Skip to content

Commit

Permalink
fixup! Index Release sections by Suite
Browse files Browse the repository at this point in the history
  • Loading branch information
woky committed Jul 12, 2023
1 parent acec8da commit 7cc583e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
72 changes: 72 additions & 0 deletions internal/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ func (s *httpSuite) TestDoError(c *C) {
}

func (s *httpSuite) prepareArchive(suite, version, arch string, components []string) *testarchive.Release {
return s.prepareArchiveAdjustRelease(suite, version, arch, components, nil)
}

func (s *httpSuite) prepareArchiveAdjustRelease(suite, version, arch string, components []string, adjustRelease func(*testarchive.Release)) *testarchive.Release {
release := &testarchive.Release{
Suite: suite,
Version: version,
Label: "Ubuntu",
}
for i, component := range components {
index := &testarchive.PackageIndex{
Expand All @@ -114,6 +119,9 @@ func (s *httpSuite) prepareArchive(suite, version, arch string, components []str
if err != nil {
panic(err)
}
if adjustRelease != nil {
adjustRelease(release)
}
release.Render(base.Path, s.responses)
return release
}
Expand Down Expand Up @@ -260,6 +268,70 @@ func (s *httpSuite) TestFetchSecurityPackage(c *C) {
c.Assert(read(pkg), Equals, "mypkg2 1.2 data")
}

func (s *httpSuite) TestArchiveLabels(c *C) {
setLabel := func(label string) func(*testarchive.Release) {
return func(r *testarchive.Release) {
r.Label = label
}
}

s.prepareArchive("jammy", "22.04", "amd64", []string{"main", "universe"})

options := archive.Options{
Label: "ubuntu",
Version: "22.04",
Arch: "amd64",
Suites: []string{"jammy"},
Components: []string{"main", "universe"},
CacheDir: c.MkDir(),
}

_, err := archive.Open(&options)
c.Assert(err, IsNil)

s.prepareArchiveAdjustRelease("jammy", "22.04", "amd64", []string{"main", "universe"}, setLabel("Ubuntu"))

options = archive.Options{
Label: "ubuntu",
Version: "22.04",
Arch: "amd64",
Suites: []string{"jammy"},
Components: []string{"main", "universe"},
CacheDir: c.MkDir(),
}

_, err = archive.Open(&options)
c.Assert(err, IsNil)

s.prepareArchiveAdjustRelease("jammy", "22.04", "amd64", []string{"main", "universe"}, setLabel("UbuntuProFIPS"))

options = archive.Options{
Label: "ubuntu",
Version: "22.04",
Arch: "amd64",
Suites: []string{"jammy"},
Components: []string{"main", "universe"},
CacheDir: c.MkDir(),
}

_, err = archive.Open(&options)
c.Assert(err, IsNil)

s.prepareArchiveAdjustRelease("jammy", "22.04", "amd64", []string{"main", "universe"}, setLabel("ThirdParty"))

options = archive.Options{
Label: "ubuntu",
Version: "22.04",
Arch: "amd64",
Suites: []string{"jammy"},
Components: []string{"main", "universe"},
CacheDir: c.MkDir(),
}

_, err = archive.Open(&options)
c.Assert(err, ErrorMatches, `.*\bno Ubuntu section`)
}

func read(r io.Reader) string {
data, err := ioutil.ReadAll(r)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/archive/testarchive/testarchive.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (p *Package) Content() []byte {
type Release struct {
Suite string
Version string
Label string
Items []Item
}

Expand All @@ -124,7 +125,7 @@ func (r *Release) Content() []byte {
}
content := fmt.Sprintf(string(testutil.Reindent(`
Origin: Ubuntu
Label: Ubuntu
Label: %s
Suite: %s
Version: %s
Codename: codename
Expand All @@ -134,7 +135,7 @@ func (r *Release) Content() []byte {
Description: Ubuntu %s
SHA256:
%s
`)), r.Suite, r.Version, r.Version, digests.String())
`)), r.Label, r.Suite, r.Version, r.Version, digests.String())

return []byte(content)
}
Expand Down

0 comments on commit 7cc583e

Please sign in to comment.