debian-forge-composer/internal/mocks/rpmmd/fixtures.go
Tomáš Hozza 625b1578fa Port osbuild/images v0.33.0 with dot-notation to composer
Update the osbuild/images to the version which introduces "dot notation"
for distro release versions.

 - Replace all uses of distroregistry by distrofactory.
 - Delete local version of reporegistry and use the one from the
   osbuild/images.
 - Weldr: unify `createWeldrAPI()` and `createWeldrAPI2()` into a single
   `createTestWeldrAPI()` function`.
 - store/fixture: rework fixtures to allow overriding the host distro
   name and host architecture name. A cleanup function to restore the
   host distro and arch names is always part of the fixture struct.
 - Delete `distro_mock` package, since it is no longer used.
 - Bump the required version of osbuild to 98, because the OSCAP
   customization is using the 'compress_results' stage option, which is
   not available in older versions of osbuild.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-01-26 11:32:34 +01:00

86 lines
2.3 KiB
Go

package rpmmd_mock
import (
"os"
"path"
"github.com/osbuild/osbuild-composer/internal/jobqueue/fsjobqueue"
dnfjson_mock "github.com/osbuild/osbuild-composer/internal/mocks/dnfjson"
"github.com/osbuild/osbuild-composer/internal/store"
"github.com/osbuild/osbuild-composer/internal/worker"
)
type FixtureGenerator func(tmpdir, hostDistroName, hostArchName string) Fixture
func createBaseWorkersFixture(tmpdir string) *worker.Server {
q, err := fsjobqueue.New(tmpdir)
if err != nil {
panic(err)
}
return worker.NewServer(nil, q, worker.Config{BasePath: "/api/worker/v1"})
}
func BaseFixture(tmpdir, hostDistroName, hostArchName string) Fixture {
return Fixture{
store.FixtureBase(hostDistroName, hostArchName),
createBaseWorkersFixture(tmpdir),
dnfjson_mock.Base,
}
}
func NoComposesFixture(tmpdir, hostDistroName, hostArchName string) Fixture {
return Fixture{
store.FixtureEmpty(hostDistroName, hostArchName),
createBaseWorkersFixture(tmpdir),
dnfjson_mock.Base,
}
}
func NonExistingPackage(tmpdir, hostDistroName, hostArchName string) Fixture {
return Fixture{
store.FixtureBase(hostDistroName, hostArchName),
createBaseWorkersFixture(tmpdir),
dnfjson_mock.NonExistingPackage,
}
}
func BadDepsolve(tmpdir, hostDistroName, hostArchName string) Fixture {
return Fixture{
store.FixtureBase(hostDistroName, hostArchName),
createBaseWorkersFixture(tmpdir),
dnfjson_mock.BadDepsolve,
}
}
func BadFetch(tmpdir, hostDistroName, hostArchName string) Fixture {
return Fixture{
store.FixtureBase(hostDistroName, hostArchName),
createBaseWorkersFixture(tmpdir),
dnfjson_mock.BadFetch,
}
}
func OldChangesFixture(tmpdir, hostDistroName, hostArchName string) Fixture {
return Fixture{
store.FixtureOldChanges(hostDistroName, hostArchName),
createBaseWorkersFixture(tmpdir),
dnfjson_mock.Base,
}
}
func BadJobJSONFixture(tmpdir, hostDistroName, hostArchName string) Fixture {
err := os.Mkdir(path.Join(tmpdir, "/jobs"), 0755)
if err != nil {
panic(err)
}
err = os.WriteFile(path.Join(tmpdir, "/jobs/30000000-0000-0000-0000-000000000005.json"), []byte("{invalid json content"), 0600)
if err != nil {
panic(err)
}
return Fixture{
store.FixtureJobs(hostDistroName, hostArchName),
createBaseWorkersFixture(path.Join(tmpdir, "/jobs")),
dnfjson_mock.Base,
}
}