Skip to content

Commit

Permalink
reporegistry: export ReposByImageTypeName instead of ReposByImageType
Browse files Browse the repository at this point in the history
Let's export ReposByImageTypeName(), which accepts distro, arch and
image type names as strings, instead of just `distro.ImageType`. This
has the advantage, that the caller may actually use a distro name alias
to get repositories, instead of the actual distro name that the image
type is associated with.

The ReposByImageType() is removed in favor of ReposByImageTypeName().

Signed-off-by: Tomáš Hozza <[email protected]>
  • Loading branch information
thozza authored and achilleas-k committed Jan 25, 2024
1 parent 8c10f3d commit f8b7d00
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 45 deletions.
20 changes: 2 additions & 18 deletions pkg/reporegistry/reporegistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package reporegistry

import (
"fmt"
"reflect"

"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/distroidparser"
"github.com/osbuild/images/pkg/rpmmd"
)
Expand Down Expand Up @@ -38,26 +36,12 @@ func NewFromDistrosRepoConfigs(distrosRepoConfigs rpmmd.DistrosRepoConfigs) *Rep
return &RepoRegistry{distrosRepoConfigs}
}

// ReposByImageType returns a slice of rpmmd.RepoConfig instances, which should be used for building the specific
// image type. All repositories for the associated distribution and architecture, without any ImageTypeTags set,
// are always part of the returned slice. In addition, if there are repositories tagged with the specific image
// type name, these are added to the returned slice as well.
func (r *RepoRegistry) ReposByImageType(imageType distro.ImageType) ([]rpmmd.RepoConfig, error) {
if imageType.Arch() == nil || reflect.ValueOf(imageType.Arch()).IsNil() {
return nil, fmt.Errorf("there is no architecture associated with the provided image type")
}
if imageType.Arch().Distro() == nil || reflect.ValueOf(imageType.Arch().Distro()).IsNil() {
return nil, fmt.Errorf("there is no distribution associated with the architecture associated with the provided image type")
}
return r.reposByImageTypeName(imageType.Arch().Distro().Name(), imageType.Arch().Name(), imageType.Name())
}

// reposByImageTypeName returns a slice of rpmmd.RepoConfig instances, which should be used for building the specific
// ReposByImageTypeName returns a slice of rpmmd.RepoConfig instances, which should be used for building the specific
// image type name (of a given distribution and architecture). The method does not verify
// if the given image type name is actually part of the architecture definition of the provided name.
// Therefore in general, all common distro-arch-specific repositories are returned for any image type name,
// even for non-existing ones.
func (r *RepoRegistry) reposByImageTypeName(distro, arch, imageType string) ([]rpmmd.RepoConfig, error) {
func (r *RepoRegistry) ReposByImageTypeName(distro, arch, imageType string) ([]rpmmd.RepoConfig, error) {
repositories := []rpmmd.RepoConfig{}

archRepos, err := r.ReposByArchName(distro, arch, true)
Expand Down
30 changes: 3 additions & 27 deletions pkg/reporegistry/reporegistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,9 @@ func TestReposByImageType_reposByImageTypeName(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := rr.ReposByImageType(tt.args.input)
got, err := rr.ReposByImageTypeName(tt.args.input.Arch().Distro().Name(), tt.args.input.Arch().Name(), tt.args.input.Name())
assert.Nil(t, err)

var gotNames []string
for _, r := range got {
gotNames = append(gotNames, r.Name)
}

if !reflect.DeepEqual(gotNames, tt.want) {
t.Errorf("ReposByImageType() =\n got: %#v\n want: %#v", gotNames, tt.want)
}

got, err = rr.reposByImageTypeName(tt.args.input.Arch().Distro().Name(), tt.args.input.Arch().Name(), tt.args.input.Name())
assert.Nil(t, err)
gotNames = []string{}
gotNames := []string{}
for _, r := range got {
gotNames = append(gotNames, r.Name)
}
Expand All @@ -121,18 +109,6 @@ func TestReposByImageType_reposByImageTypeName(t *testing.T) {
}
}

// TestInvalidReposByImageType tests return values from ReposByImageType
// for invalid values
func TestInvalidReposByImageType(t *testing.T) {
rr := getTestingRepoRegistry()

ti := test_distro.TestImageType{}

repos, err := rr.ReposByImageType(&ti)
assert.Nil(t, repos)
assert.NotNil(t, err)
}

// TestInvalidreposByImageTypeName tests return values from reposByImageTypeName
// for invalid distro name, arch and image type
func TestInvalidreposByImageTypeName(t *testing.T) {
Expand Down Expand Up @@ -222,7 +198,7 @@ func TestInvalidreposByImageTypeName(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := rr.reposByImageTypeName(tt.args.distro, tt.args.arch, tt.args.imageType)
got, err := rr.ReposByImageTypeName(tt.args.distro, tt.args.arch, tt.args.imageType)
assert.True(t, tt.want(got, err))
})
}
Expand Down

0 comments on commit f8b7d00

Please sign in to comment.