Move kernelVerStr() from distros to rpmmd
Move the `kernelVerStr()` function duplicated in many distro definitions to the `rpmmd` package as `GetVerStrFromPackageSpecListPanic()`. I could not come up with a better name, sorry. This will prevent creating another copy of the code in rhel-84 for the `gce` image. This change initially exposed a bug in the original implementation of `kernelVerStr()`. Since on the first line, we allocate an empty structure into `kernelPkg` variable, it can never be `nil` and the function never panicked even if there was no `kernel` package in the PackageSpec list. Fix all unit tests to provide valid arguments when calling `Manifest()` method of image types. Signed-off-by: Tomas Hozza <thozza@redhat.com> kernelVerStr fixup Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
a392d71da6
commit
8713b8002a
10 changed files with 122 additions and 118 deletions
|
|
@ -203,6 +203,23 @@ func (re *RepositoryError) Error() string {
|
|||
return re.msg
|
||||
}
|
||||
|
||||
func GetVerStrFromPackageSpecList(pkgs []PackageSpec, packageName string) (string, error) {
|
||||
for _, pkg := range pkgs {
|
||||
if pkg.Name == packageName {
|
||||
return fmt.Sprintf("%s-%s.%s", pkg.Version, pkg.Release, pkg.Arch), nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("package %q not found in the PackageSpec list", packageName)
|
||||
}
|
||||
|
||||
func GetVerStrFromPackageSpecListPanic(pkgs []PackageSpec, packageName string) string {
|
||||
pkgVerStr, err := GetVerStrFromPackageSpecList(pkgs, packageName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return pkgVerStr
|
||||
}
|
||||
|
||||
func loadRepositoriesFromFile(filename string) (map[string][]RepoConfig, error) {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue