distro: make it impossible to initialize registry with nil values

The current `NewRegistry` implementation allows for nil values in the
map, but this leads to subtle bugs when using the registry. This patch
enforces non-nil values by introducing additional checks before we
insert the value into the map.

The change unfortunately breaks a lot of tests and therefore it is
necessary to create additional mock: distro.

The new mock is used instead of the previous "real" implementation,
which used to contain nil values.
This commit is contained in:
Martin Sehnoutka 2020-02-19 11:46:29 +01:00 committed by Tom Gundersen
parent fae51095d2
commit 8e77e03284
4 changed files with 44 additions and 11 deletions

View file

@ -0,0 +1,14 @@
package distro_mock
import (
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
)
func NewRegistry() *distro.Registry {
ftest := fedoratest.New()
if ftest == nil {
panic("Attempt to register Fedora test failed")
}
return distro.WithSingleDistro(ftest)
}

View file

@ -4,7 +4,7 @@ import (
"fmt"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/compose"
"github.com/osbuild/osbuild-composer/internal/distro"
distro_mock "github.com/osbuild/osbuild-composer/internal/mocks/distro"
"sort"
"time"
@ -94,7 +94,7 @@ func createBaseStoreFixture() *store.Store {
}
d := test_distro.New()
r := distro.NewRegistry([]string{"."})
r := distro_mock.NewRegistry()
s := store.New(nil, d, *r)
s.Blueprints[bName] = b
@ -184,7 +184,7 @@ func createStoreWithoutComposesFixture() *store.Store {
}
d := test_distro.New()
r := distro.NewRegistry([]string{"."})
r := distro_mock.NewRegistry()
s := store.New(nil, d, *r)
s.Blueprints[bName] = b