distro: rename awkwardly named function
WithSingleDistro() doesn't follow go's naming convention for creating objects (New*). Rename it to NewRegistry() and rename the old NewRegistry() to NewDefaultRegistry(). The idea is that NewRegistry() can be used to create full Registry objects from outside the package. NewDefaultRegistry() is a convenience function that creates a Registry with all known distros.
This commit is contained in:
parent
60301df8f7
commit
e5eb673be6
14 changed files with 29 additions and 26 deletions
|
|
@ -80,7 +80,7 @@ func main() {
|
|||
}
|
||||
|
||||
rpm := rpmmd.NewRPMMD(path.Join(cacheDirectory, "rpmmd"))
|
||||
distros := distro.NewRegistry([]string{"/etc/osbuild-composer", "/usr/share/osbuild-composer"})
|
||||
distros := distro.NewDefaultRegistry([]string{"/etc/osbuild-composer", "/usr/share/osbuild-composer"})
|
||||
|
||||
distribution, err := distros.FromHost()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
distros := distro.NewRegistry([]string{"."})
|
||||
distros := distro.NewDefaultRegistry([]string{"."})
|
||||
d := distros.GetDistro(distroArg)
|
||||
if d == nil {
|
||||
panic("unknown distro: " + distroArg)
|
||||
|
|
|
|||
|
|
@ -70,15 +70,18 @@ type Registry struct {
|
|||
distros map[common.Distribution]Distro
|
||||
}
|
||||
|
||||
func WithSingleDistro(dist Distro) *Registry {
|
||||
func NewRegistry(distros ...Distro) *Registry {
|
||||
reg := &Registry{
|
||||
distros: make(map[common.Distribution]Distro),
|
||||
}
|
||||
reg.register(dist)
|
||||
for _, dist := range distros {
|
||||
reg.register(dist)
|
||||
}
|
||||
return reg
|
||||
}
|
||||
|
||||
func NewRegistry(confPaths []string) *Registry {
|
||||
// Create a new Registry containing all known distros.
|
||||
func NewDefaultRegistry(confPaths []string) *Registry {
|
||||
distros := &Registry{
|
||||
distros: make(map[common.Distribution]Distro),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func TestDistro_Pipeline(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
t.Run(tt.Compose.OutputFormat, func(t *testing.T) {
|
||||
distros := distro.NewRegistry([]string{"../.."})
|
||||
distros := distro.NewDefaultRegistry([]string{"../.."})
|
||||
d := distros.GetDistro(tt.Compose.Distro)
|
||||
if d == nil {
|
||||
t.Errorf("unknown distro: %v", tt.Compose.Distro)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ func TestListOutputFormats(t *testing.T) {
|
|||
"vmdk",
|
||||
}
|
||||
|
||||
distros := distro.NewRegistry([]string{"../../../"})
|
||||
distros := distro.NewDefaultRegistry([]string{"../../../"})
|
||||
f30 := distros.GetDistro("fedora-30")
|
||||
if got := f30.ListOutputFormats(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("ListOutputFormats() = %v, want %v", got, want)
|
||||
|
|
@ -93,7 +93,7 @@ func TestFilenameFromType(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
distros := distro.NewRegistry([]string{"../../../"})
|
||||
distros := distro.NewDefaultRegistry([]string{"../../../"})
|
||||
f30 := distros.GetDistro("fedora-30")
|
||||
got, got1, err := f30.FilenameFromType(tt.args.outputFormat)
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ func TestListOutputFormats(t *testing.T) {
|
|||
"vmdk",
|
||||
}
|
||||
|
||||
distros := distro.NewRegistry([]string{"../../../"})
|
||||
distros := distro.NewDefaultRegistry([]string{"../../../"})
|
||||
f31 := distros.GetDistro("fedora-31")
|
||||
if got := f31.ListOutputFormats(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("ListOutputFormats() = %v, want %v", got, want)
|
||||
|
|
@ -93,7 +93,7 @@ func TestFilenameFromType(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
distros := distro.NewRegistry([]string{"../../../"})
|
||||
distros := distro.NewDefaultRegistry([]string{"../../../"})
|
||||
f31 := distros.GetDistro("fedora-31")
|
||||
got, got1, err := f31.FilenameFromType(tt.args.outputFormat)
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ func TestListOutputFormats(t *testing.T) {
|
|||
"vmdk",
|
||||
}
|
||||
|
||||
distros := distro.NewRegistry([]string{"../../../"})
|
||||
distros := distro.NewDefaultRegistry([]string{"../../../"})
|
||||
f32 := distros.GetDistro("fedora-32")
|
||||
if got := f32.ListOutputFormats(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("ListOutputFormats() = %v, want %v", got, want)
|
||||
|
|
@ -93,7 +93,7 @@ func TestFilenameFromType(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
distros := distro.NewRegistry([]string{"../../../"})
|
||||
distros := distro.NewDefaultRegistry([]string{"../../../"})
|
||||
f32 := distros.GetDistro("fedora-32")
|
||||
got, got1, err := f32.FilenameFromType(tt.args.outputFormat)
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ func TestListOutputFormats(t *testing.T) {
|
|||
"vmdk",
|
||||
}
|
||||
|
||||
distros := distro.NewRegistry([]string{"../../../"})
|
||||
distros := distro.NewDefaultRegistry([]string{"../../../"})
|
||||
rhel81 := distros.GetDistro("rhel-8.2")
|
||||
if got := rhel81.ListOutputFormats(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("ListOutputFormats() = %v, want %v", got, want)
|
||||
|
|
@ -93,7 +93,7 @@ func TestFilenameFromType(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
distros := distro.NewRegistry([]string{"../../../"})
|
||||
distros := distro.NewDefaultRegistry([]string{"../../../"})
|
||||
rhel81 := distros.GetDistro("rhel-8.2")
|
||||
got, got1, err := rhel81.FilenameFromType(tt.args.outputFormat)
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ func TestListOutputFormats(t *testing.T) {
|
|||
"vmdk",
|
||||
}
|
||||
|
||||
distros := distro.NewRegistry([]string{"../../../"})
|
||||
distros := distro.NewDefaultRegistry([]string{"../../../"})
|
||||
rhel82 := distros.GetDistro("rhel-8.2")
|
||||
if got := rhel82.ListOutputFormats(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("ListOutputFormats() = %v, want %v", got, want)
|
||||
|
|
@ -93,7 +93,7 @@ func TestFilenameFromType(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
distros := distro.NewRegistry([]string{"../../../"})
|
||||
distros := distro.NewDefaultRegistry([]string{"../../../"})
|
||||
rhel82 := distros.GetDistro("rhel-8.2")
|
||||
got, got1, err := rhel82.FilenameFromType(tt.args.outputFormat)
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ func TestBasic(t *testing.T) {
|
|||
|
||||
for _, c := range cases {
|
||||
distroStruct := test_distro.New()
|
||||
registry := distro_mock.NewRegistry()
|
||||
registry := distro_mock.NewDefaultRegistry()
|
||||
api := jobqueue.New(nil, store.New(nil, distroStruct, *registry))
|
||||
|
||||
test.TestNonJsonRoute(t, api, false, c.Method, c.Path, c.Body, c.ExpectedStatus, c.ExpectedResponse)
|
||||
|
|
@ -44,7 +44,7 @@ func TestBasic(t *testing.T) {
|
|||
func TestCreate(t *testing.T) {
|
||||
id, _ := uuid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff")
|
||||
distroStruct := test_distro.New()
|
||||
registry := distro_mock.NewRegistry()
|
||||
registry := distro_mock.NewDefaultRegistry()
|
||||
store := store.New(nil, distroStruct, *registry)
|
||||
api := jobqueue.New(nil, store)
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ func TestCreate(t *testing.T) {
|
|||
func testUpdateTransition(t *testing.T, from, to string, expectedStatus int, expectedResponse string) {
|
||||
id, _ := uuid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff")
|
||||
distroStruct := test_distro.New()
|
||||
registry := distro_mock.NewRegistry()
|
||||
registry := distro_mock.NewDefaultRegistry()
|
||||
store := store.New(nil, distroStruct, *registry)
|
||||
api := jobqueue.New(nil, store)
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ func (e *TargetsError) Error() string {
|
|||
}
|
||||
|
||||
func (job *Job) Run(uploader LocalTargetUploader) (*common.ComposeResult, error) {
|
||||
distros := distro.NewRegistry([]string{"/etc/osbuild-composer", "/usr/share/osbuild-composer"})
|
||||
distros := distro.NewDefaultRegistry([]string{"/etc/osbuild-composer", "/usr/share/osbuild-composer"})
|
||||
d := distros.GetDistro(job.Distro)
|
||||
if d == nil {
|
||||
return nil, fmt.Errorf("unknown distro: %s", job.Distro)
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
|
||||
)
|
||||
|
||||
func NewRegistry() *distro.Registry {
|
||||
func NewDefaultRegistry() *distro.Registry {
|
||||
ftest := fedoratest.New()
|
||||
if ftest == nil {
|
||||
panic("Attempt to register Fedora test failed")
|
||||
}
|
||||
return distro.WithSingleDistro(ftest)
|
||||
return distro.NewRegistry(ftest)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ func createBaseStoreFixture() *store.Store {
|
|||
}
|
||||
|
||||
d := test_distro.New()
|
||||
r := distro_mock.NewRegistry()
|
||||
r := distro_mock.NewDefaultRegistry()
|
||||
s := store.New(nil, d, *r)
|
||||
|
||||
s.Blueprints[bName] = b
|
||||
|
|
@ -191,7 +191,7 @@ func createStoreWithoutComposesFixture() *store.Store {
|
|||
}
|
||||
|
||||
d := test_distro.New()
|
||||
r := distro_mock.NewRegistry()
|
||||
r := distro_mock.NewDefaultRegistry()
|
||||
s := store.New(nil, d, *r)
|
||||
|
||||
s.Blueprints[bName] = b
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ func TestBasicRcmAPI(t *testing.T) {
|
|||
{"GET", "/v1/compose/7802c476-9cd1-41b7-ba81-43c1906bce73", `{"status":"RUNNING"}`, "application/json", http.StatusBadRequest, `{"error_reason":"Compose UUID does not exist"}`},
|
||||
}
|
||||
|
||||
registry := distro_mock.NewRegistry()
|
||||
registry := distro_mock.NewDefaultRegistry()
|
||||
distroStruct := fedoratest.New()
|
||||
api := rcm.New(nil, store.New(nil, distroStruct, *registry), rpmmd_mock.NewRPMMDMock(rpmmd_mock.BaseFixture()))
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ func TestBasicRcmAPI(t *testing.T) {
|
|||
func TestSubmitCompose(t *testing.T) {
|
||||
// Test the most basic use case: Submit a new job and get its status.
|
||||
distroStruct := fedoratest.New()
|
||||
registry := distro_mock.NewRegistry()
|
||||
registry := distro_mock.NewDefaultRegistry()
|
||||
api := rcm.New(nil, store.New(nil, distroStruct, *registry), rpmmd_mock.NewRPMMDMock(rpmmd_mock.BaseFixture()))
|
||||
|
||||
var submit_reply struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue