distro: panic less often
Return errors from all distro's New() functions instead of logging and returning nil. Also, return errors instead of panicking from NewRegistry() and NewDefaultRegistry().
This commit is contained in:
parent
d1965d6268
commit
87e9c39532
19 changed files with 128 additions and 62 deletions
|
|
@ -34,7 +34,10 @@ func TestBasic(t *testing.T) {
|
|||
|
||||
for _, c := range cases {
|
||||
distroStruct := test_distro.New()
|
||||
registry := distro_mock.NewDefaultRegistry()
|
||||
registry, err := distro_mock.NewDefaultRegistry()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
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,11 +47,14 @@ 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.NewDefaultRegistry()
|
||||
registry, err := distro_mock.NewDefaultRegistry()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := store.New(nil, distroStruct, *registry)
|
||||
api := jobqueue.New(nil, store)
|
||||
|
||||
err := store.PushCompose(id, &blueprint.Blueprint{}, nil, nil, map[string]string{"test-repo": "test:foo"}, "x86_64", "qcow2", 0, nil)
|
||||
err = store.PushCompose(id, &blueprint.Blueprint{}, nil, nil, map[string]string{"test-repo": "test:foo"}, "x86_64", "qcow2", 0, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("error pushing compose: %v", err)
|
||||
}
|
||||
|
|
@ -60,7 +66,10 @@ 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.NewDefaultRegistry()
|
||||
registry, err := distro_mock.NewDefaultRegistry()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := store.New(nil, distroStruct, *registry)
|
||||
api := jobqueue.New(nil, store)
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,11 @@ func (e *TargetsError) Error() string {
|
|||
}
|
||||
|
||||
func (job *Job) Run(uploader LocalTargetUploader) (*common.ComposeResult, error) {
|
||||
distros := distro.NewDefaultRegistry([]string{"/etc/osbuild-composer", "/usr/share/osbuild-composer"})
|
||||
distros, err := distro.NewDefaultRegistry([]string{"/etc/osbuild-composer", "/usr/share/osbuild-composer"})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading distros: %v", err)
|
||||
}
|
||||
|
||||
d := distros.GetDistro(job.Distro)
|
||||
if d == nil {
|
||||
return nil, fmt.Errorf("unknown distro: %s", job.Distro)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue