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

@ -1,11 +1,11 @@
package jobqueue_test
import (
distro_mock "github.com/osbuild/osbuild-composer/internal/mocks/distro"
"net/http"
"testing"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/distro"
test_distro "github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
"github.com/osbuild/osbuild-composer/internal/jobqueue"
"github.com/osbuild/osbuild-composer/internal/store"
@ -34,7 +34,7 @@ func TestBasic(t *testing.T) {
for _, c := range cases {
distroStruct := test_distro.New()
registry := distro.NewRegistry([]string{"."})
registry := distro_mock.NewRegistry()
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.NewRegistry([]string{"."})
registry := distro_mock.NewRegistry()
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.NewRegistry([]string{"."})
registry := distro_mock.NewRegistry()
store := store.New(nil, distroStruct, *registry)
api := jobqueue.New(nil, store)