Skip to content

Commit

Permalink
fix: empty priority is no longer valid
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Oct 18, 2024
1 parent 4962b27 commit 418ea0d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
23 changes: 17 additions & 6 deletions internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ type yamlArchive struct {
Version string `yaml:"version"`
Suites []string `yaml:"suites"`
Components []string `yaml:"components"`
Priority int `yaml:"priority"`
Priority *int `yaml:"priority"`
Default bool `yaml:"default"`
PubKeys []string `yaml:"public-keys"`
}
Expand Down Expand Up @@ -542,6 +542,7 @@ func parseRelease(baseDir, filePath string, data []byte) (*Release, error) {
// not being used, we will revert back to the default archive behaviour.
hasPriority := false
var defaultArchive string
var archiveNoPriority string
for archiveName, details := range yamlVar.Archives {
if details.Version == "" {
return nil, fmt.Errorf("%s: archive %q missing version field", fileName, archiveName)
Expand Down Expand Up @@ -572,18 +573,28 @@ func parseRelease(baseDir, filePath string, data []byte) (*Release, error) {
}
archiveKeys = append(archiveKeys, key)
}
if details.Priority > MaxArchivePriority || details.Priority < MinArchivePriority {
return nil, fmt.Errorf("%s: archive %q has invalid priority value of %d", fileName, archiveName, details.Priority)
}
if details.Priority != 0 {
priority := 0
if details.Priority != nil {
hasPriority = true
if archiveNoPriority != "" {
return nil, fmt.Errorf("%s: archive %q missing priority", fileName, archiveNoPriority)
}
priority = *details.Priority
if priority > MaxArchivePriority || priority < MinArchivePriority {
return nil, fmt.Errorf("%s: archive %q has invalid priority value of %d", fileName, archiveName, priority)
}
} else {
if hasPriority {
return nil, fmt.Errorf("%s: archive %q missing priority", fileName, archiveName)
}
archiveNoPriority = archiveName
}
release.Archives[archiveName] = &Archive{
Name: archiveName,
Version: details.Version,
Suites: details.Suites,
Components: details.Components,
Priority: details.Priority,
Priority: priority,
PubKeys: archiveKeys,
}
}
Expand Down
53 changes: 53 additions & 0 deletions internal/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,59 @@ var setupTests = []setupTest{{
},
},
},
}, {
summary: "Multiple archives inconsistent use of priorities",
input: map[string]string{
"chisel.yaml": `
format: v1
archives:
foo:
version: 22.04
components: [main, universe]
suites: [jammy]
priority: 20
public-keys: [test-key]
bar:
version: 22.04
components: [universe]
suites: [jammy-updates]
public-keys: [test-key]
public-keys:
test-key:
id: ` + testKey.ID + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
`,
"slices/mydir/mypkg.yaml": `
package: mypkg
`,
},
relerror: `chisel.yaml: archive "bar" missing priority`,
}, {
summary: "Multiple archives with no priorities",
input: map[string]string{
"chisel.yaml": `
format: v1
archives:
foo:
version: 22.04
components: [main, universe]
suites: [jammy]
public-keys: [test-key]
bar:
version: 22.04
components: [universe]
suites: [jammy-updates]
public-keys: [test-key]
public-keys:
test-key:
id: ` + testKey.ID + `
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
`,
"slices/mydir/mypkg.yaml": `
package: mypkg
`,
},
relerror: `chisel.yaml: archives "bar" and "foo" have the same priority value of 0`,
}, {
summary: "Archive with suites unset",
input: map[string]string{
Expand Down

0 comments on commit 418ea0d

Please sign in to comment.