diff --git a/pkg/reporegistry/reporegistry.go b/pkg/reporegistry/reporegistry.go index 43db679373..aab3594817 100644 --- a/pkg/reporegistry/reporegistry.go +++ b/pkg/reporegistry/reporegistry.go @@ -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" ) @@ -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) diff --git a/pkg/reporegistry/reporegistry_test.go b/pkg/reporegistry/reporegistry_test.go index 8e58bd3841..7124f42cad 100644 --- a/pkg/reporegistry/reporegistry_test.go +++ b/pkg/reporegistry/reporegistry_test.go @@ -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) } @@ -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) { @@ -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)) }) }