Skip to content

Commit

Permalink
Fixing tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Fiehe <[email protected]>
  • Loading branch information
Christoph Fiehe committed Oct 10, 2024
1 parent b76fefa commit e21c4a9
Show file tree
Hide file tree
Showing 25 changed files with 78 additions and 91 deletions.
13 changes: 12 additions & 1 deletion api/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,17 @@ func apiPublishUpdateSwitch(c *gin.Context) {
published.MultiDist = *b.MultiDist
}

revision := published.ObtainRevision()
sources := revision.Sources

if published.SourceKind == deb.SourceSnapshot {
for _, snapshotInfo := range b.Snapshots {
component := snapshotInfo.Component
name := snapshotInfo.Name
sources[component] = name
}
}

resources := []string{string(published.Key())}
taskName := fmt.Sprintf("Update published %s repository %s/%s", published.SourceKind, published.StoragePrefix(), published.Distribution)
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
Expand Down Expand Up @@ -576,7 +587,7 @@ func apiPublishSourcesList(c *gin.Context) {
return
}

Check warning on line 588 in api/publish.go

View check run for this annotation

Codecov / codecov/patch

api/publish.go#L584-L588

Added lines #L584 - L588 were not covered by tests

c.JSON(http.StatusOK, revision.ToJSON()["Sources"])
c.JSON(http.StatusOK, revision.SourceList())

Check warning on line 590 in api/publish.go

View check run for this annotation

Codecov / codecov/patch

api/publish.go#L590

Added line #L590 was not covered by tests
}

// @Router /api/publish/{prefix}/{distribution}/sources [put]
Expand Down
2 changes: 1 addition & 1 deletion cmd/publish_source_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func aptlyPublishSourceListTxt(published *deb.PublishedRepo) error {
func aptlyPublishSourceListJSON(published *deb.PublishedRepo) error {
revision := published.Revision

output, err := json.MarshalIndent(revision.ToJSON()["Sources"], "", " ")
output, err := json.MarshalIndent(revision.SourceList(), "", " ")
if err != nil {
return fmt.Errorf("unable to list: %s", err)
}

Check warning on line 63 in cmd/publish_source_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/publish_source_list.go#L57-L63

Added lines #L57 - L63 were not covered by tests
Expand Down
51 changes: 28 additions & 23 deletions deb/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import (
"github.com/aptly-dev/aptly/utils"
)

type SourceEntry struct {
Component, Name string
}

type PublishedRepoUpdateResult struct {
AddedSources map[string]string
UpdatedSources map[string]string
Expand Down Expand Up @@ -129,6 +133,21 @@ func (revision *PublishedRepoRevision) Components() []string {
return components

Check warning on line 133 in deb/publish.go

View check run for this annotation

Codecov / codecov/patch

deb/publish.go#L126-L133

Added lines #L126 - L133 were not covered by tests
}

func (revision *PublishedRepoRevision) SourceList() []SourceEntry {
sources := revision.Sources
components := revision.Components()
sourceList := make([]SourceEntry, 0, len(sources))
for _, component := range components {
name := sources[component]
sourceList = append(sourceList, SourceEntry{
Component: component,
Name: name,
})
}

Check warning on line 146 in deb/publish.go

View check run for this annotation

Codecov / codecov/patch

deb/publish.go#L136-L146

Added lines #L136 - L146 were not covered by tests

return sourceList

Check warning on line 148 in deb/publish.go

View check run for this annotation

Codecov / codecov/patch

deb/publish.go#L148

Added line #L148 was not covered by tests
}

func (revision *PublishedRepoRevision) SourceNames() []string {
sources := revision.Sources
names := make([]string, 0, len(sources))
Expand Down Expand Up @@ -449,40 +468,26 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri
return result, nil
}

type sourceInfo struct {
Component, Name string
}

func (revision *PublishedRepoRevision) ToJSON() map[string]any {
sources := []sourceInfo{}
for _, component := range revision.Components() {
name := revision.Sources[component]
sources = append(sources, sourceInfo{
Component: component,
Name: name,
})
}
return map[string]any{"Sources": sources}
}

func (revision *PublishedRepoRevision) MarshalJSON() ([]byte, error) {
sources := []sourceInfo{}
for _, component := range revision.Components() {
name := revision.Sources[component]
sources = append(sources, sourceInfo{
sources := revision.Sources
components := revision.Components()
sourceList := make([]SourceEntry, 0, len(sources))
for _, component := range components {
name := sources[component]
sourceList = append(sourceList, SourceEntry{
Component: component,
Name: name,
})

Check warning on line 480 in deb/publish.go

View check run for this annotation

Codecov / codecov/patch

deb/publish.go#L471-L480

Added lines #L471 - L480 were not covered by tests
}

return json.Marshal(map[string]interface{}{
"Sources": sources,
"Sources": sourceList,
})

Check warning on line 485 in deb/publish.go

View check run for this annotation

Codecov / codecov/patch

deb/publish.go#L483-L485

Added lines #L483 - L485 were not covered by tests
}

// MarshalJSON requires object to filled by "LoadShallow" or "LoadComplete"
func (p *PublishedRepo) MarshalJSON() ([]byte, error) {
sources := []sourceInfo{}
sources := []SourceEntry{}
for _, component := range p.Components() {
item := p.sourceItems[component]
name := ""
Expand All @@ -493,7 +498,7 @@ func (p *PublishedRepo) MarshalJSON() ([]byte, error) {
} else {
panic("no snapshot/local repo")
}
sources = append(sources, sourceInfo{
sources = append(sources, SourceEntry{
Component: component,
Name: name,
})
Expand Down
9 changes: 1 addition & 8 deletions system/t06_publish/PublishSwitch12Test_gold
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
Loading packages...
Generating metadata files and linking package files...
Finalizing metadata files...
Signing file 'Release' with gpg, please enter your passphrase when prompted:
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:
Cleaning up prefix "." components a, c...

Publish for snapshot ./maverick [i386] publishes {a: [snap2]: Created as empty}, {b: [snap2]: Created as empty}, {c: [snap3]: Created as empty} has been successfully switched to new snapshot.
ERROR: unable to switch: component c does not exist in published repository
2 changes: 0 additions & 2 deletions system/t06_publish/PublishUpdate10Test_gold
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
WARNING: force overwrite mode enabled, aptly might corrupt other published repositories sharing the same package pool.

Loading packages...
Generating metadata files and linking package files...
Finalizing metadata files...
Expand Down
1 change: 0 additions & 1 deletion system/t06_publish/PublishUpdate11Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ Generating metadata files and linking package files...
Finalizing metadata files...
Signing file 'Release' with gpg, please enter your passphrase when prompted:
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:
Cleaning up prefix "." components main...

Published local repository ./maverick [i386, source] publishes {main: [local-repo]} has been successfully updated.
1 change: 1 addition & 0 deletions system/t06_publish/PublishUpdate12Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ Generating metadata files and linking package files...
Finalizing metadata files...
Signing file 'Release' with gpg, please enter your passphrase when prompted:
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:
Cleaning up prefix "." components main...

Published local repository ./maverick [i386, source] publishes {main: [local-repo]} has been successfully updated.
2 changes: 1 addition & 1 deletion system/t06_publish/PublishUpdate13Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Signing file 'Release' with gpg, please enter your passphrase when prompted:
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:
Cleaning up prefix "." components main...

Published local repository ./maverick [i386, source] publishes {main: [local-repo]} has been successfully updated.
Published local repository ./bookworm [i386, source] publishes {main: [local-repo]} has been successfully updated.
8 changes: 0 additions & 8 deletions system/t06_publish/PublishUpdate14Test_gold

This file was deleted.

File renamed without changes.
9 changes: 8 additions & 1 deletion system/t06_publish/PublishUpdate6Test_gold
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
ERROR: unable to update: not a local repository publish
Loading packages...
Generating metadata files and linking package files...
Finalizing metadata files...
Signing file 'Release' with gpg, please enter your passphrase when prompted:
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:
Cleaning up prefix "." components contrib, main...

Published local repository ./maverick [i386, source] publishes {contrib: [repo2]}, {main: [repo1]} has been successfully updated.
4 changes: 1 addition & 3 deletions system/t06_publish/PublishUpdate7Test_gold
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Loading packages...
Generating metadata files and linking package files...
Finalizing metadata files...
Signing file 'Release' with gpg, please enter your passphrase when prompted:
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:
Cleaning up prefix "." components contrib, main...

Published local repository ./maverick [i386, source] publishes {contrib: [repo2]}, {main: [repo1]} has been successfully updated.
Published local repository ./squeeze [i386] publishes {contrib: [repo2]}, {main: [repo1]} has been successfully updated.
5 changes: 1 addition & 4 deletions system/t06_publish/PublishUpdate8Test_gold
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
Loading packages...
Generating metadata files and linking package files...
Finalizing metadata files...
Cleaning up prefix "." components contrib, main...

Published local repository ./squeeze [i386] publishes {contrib: [repo2]}, {main: [repo1]} has been successfully updated.
ERROR: unable to publish: unable to process packages: error linking file to ${HOME}/.aptly/public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz: file already exists and is different
File renamed without changes.
9 changes: 8 additions & 1 deletion system/t06_publish/PublishUpdate9Test_gold
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
WARNING: force overwrite mode enabled, aptly might corrupt other published repositories sharing the same package pool.

Loading packages...
Generating metadata files and linking package files...
ERROR: unable to publish: unable to process packages: error linking file to ${HOME}/.aptly/public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz: file already exists and is different
Finalizing metadata files...
Signing file 'Release' with gpg, please enter your passphrase when prompted:
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:
Cleaning up prefix "." components main...

Published local repository ./maverick [i386, source] publishes {main: [local-repo]} has been successfully updated.
13 changes: 3 additions & 10 deletions system/t06_publish/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,22 +424,15 @@ def check(self):

class PublishSwitch12Test(BaseTest):
"""
publish switch: add new component to publish
publish switch: wrong component names
"""
fixtureCmds = [
"aptly snapshot create snap1 empty",
"aptly snapshot create snap2 empty",
"aptly snapshot create snap3 empty",
"aptly publish snapshot -architectures=i386 -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=maverick -component=a,b snap1 snap2",
]
runCmd = "aptly publish switch -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -component=a,c maverick snap2 snap3"
gold_processor = BaseTest.expand_environ

def check(self):
super(PublishSwitch12Test, self).check()

self.check_exists('public/dists/maverick/a/binary-i386/Packages')
self.check_exists('public/dists/maverick/c/binary-i386/Packages')
runCmd = "aptly publish switch -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -component=a,c maverick snap2 snap1"
expectedCode = 1


class PublishSwitch13Test(BaseTest):
Expand Down
40 changes: 13 additions & 27 deletions system/t06_publish/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,6 @@ class PublishUpdate5Test(BaseTest):


class PublishUpdate6Test(BaseTest):
"""
publish update: not a local repo
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap1 from mirror gnuplot-maverick",
"aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap1",
]
runCmd = "aptly publish update maverick"
expectedCode = 1


class PublishUpdate7Test(BaseTest):
"""
publish update: multiple components, add some packages
"""
Expand All @@ -246,7 +232,7 @@ class PublishUpdate7Test(BaseTest):
gold_processor = BaseTest.expand_environ

def check(self):
super(PublishUpdate7Test, self).check()
super(PublishUpdate6Test, self).check()

self.check_exists('public/dists/maverick/InRelease')
self.check_exists('public/dists/maverick/Release')
Expand Down Expand Up @@ -280,7 +266,7 @@ def check(self):
self.check_file_contents('public/dists/maverick/contrib/binary-i386/Packages', 'binary2', match_prepare=lambda s: "\n".join(sorted(s.split("\n"))))


class PublishUpdate8Test(BaseTest):
class PublishUpdate7Test(BaseTest):
"""
publish update: update empty repos to empty repos
"""
Expand All @@ -293,7 +279,7 @@ class PublishUpdate8Test(BaseTest):
gold_processor = BaseTest.expand_environ


class PublishUpdate9Test(BaseTest):
class PublishUpdate8Test(BaseTest):
"""
publish update: conflicting files in the repo
"""
Expand All @@ -309,7 +295,7 @@ class PublishUpdate9Test(BaseTest):
gold_processor = BaseTest.expand_environ


class PublishUpdate10Test(BaseTest):
class PublishUpdate9Test(BaseTest):
"""
publish update: -force-overwrite
"""
Expand All @@ -324,12 +310,12 @@ class PublishUpdate10Test(BaseTest):
gold_processor = BaseTest.expand_environ

def check(self):
super(PublishUpdate10Test, self).check()
super(PublishUpdate9Test, self).check()

self.check_file_contents("public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz", "file")


class PublishUpdate11Test(BaseTest):
class PublishUpdate10Test(BaseTest):
"""
publish update: -skip-contents
"""
Expand All @@ -343,7 +329,7 @@ class PublishUpdate11Test(BaseTest):
gold_processor = BaseTest.expand_environ

def check(self):
super(PublishUpdate11Test, self).check()
super(PublishUpdate10Test, self).check()

self.check_exists('public/dists/maverick/InRelease')
self.check_exists('public/dists/maverick/Release')
Expand All @@ -353,7 +339,7 @@ def check(self):
self.check_not_exists('public/dists/maverick/main/Contents-i386.gz')


class PublishUpdate12Test(BaseTest):
class PublishUpdate11Test(BaseTest):
"""
publish update: removed some packages skipping cleanup
"""
Expand All @@ -367,7 +353,7 @@ class PublishUpdate12Test(BaseTest):
gold_processor = BaseTest.expand_environ

def check(self):
super(PublishUpdate12Test, self).check()
super(PublishUpdate11Test, self).check()

self.check_exists('public/dists/maverick/InRelease')
self.check_exists('public/dists/maverick/Release')
Expand Down Expand Up @@ -439,7 +425,7 @@ def check(self):
raise Exception("path seen wrong: %r" % (pathsSeen, ))


class PublishUpdate13Test(BaseTest):
class PublishUpdate12Test(BaseTest):
"""
publish update: -skip-bz2
"""
Expand All @@ -453,7 +439,7 @@ class PublishUpdate13Test(BaseTest):
gold_processor = BaseTest.expand_environ

def check(self):
super(PublishUpdate13Test, self).check()
super(PublishUpdate12Test, self).check()

self.check_exists('public/dists/maverick/InRelease')
self.check_exists('public/dists/maverick/Release')
Expand All @@ -464,7 +450,7 @@ def check(self):
self.check_not_exists('public/dists/maverick/main/binary-i386/Packages.bz2')


class PublishUpdate14Test(BaseTest):
class PublishUpdate13Test(BaseTest):
"""
publish update: -multi-dist
"""
Expand All @@ -477,7 +463,7 @@ class PublishUpdate14Test(BaseTest):
gold_processor = BaseTest.expand_environ

def check(self):
super(PublishUpdate14Test, self).check()
super(PublishUpdate13Test, self).check()

self.check_exists('public/dists/bookworm/InRelease')
self.check_exists('public/dists/bookworm/Release')
Expand Down

0 comments on commit e21c4a9

Please sign in to comment.