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:
parent
fae51095d2
commit
8e77e03284
4 changed files with 44 additions and 11 deletions
14
internal/mocks/distro/distro_mock.go
Normal file
14
internal/mocks/distro/distro_mock.go
Normal 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)
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue