api tests: add store fixtures
Prior this commit there wasn't an easy to populate the store. The only way was to call the weldr API or store methods. This design made testing of various edges quite hard. This commit adds store fixtures - an easy way how to define store state before each test case. In addition, the fixtures were refactored so that new instances are created prior each test. Before this change the tests were in some cases dependant on each other.
This commit is contained in:
parent
a00a0caa70
commit
66c57a05b7
3 changed files with 164 additions and 102 deletions
|
|
@ -2,10 +2,16 @@ package rpmmd_mock
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/store"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FixtureGenerator func() Fixture
|
||||
|
||||
func generatePackageList() rpmmd.PackageList {
|
||||
baseTime, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
|
||||
|
||||
|
|
@ -37,16 +43,67 @@ func generatePackageList() rpmmd.PackageList {
|
|||
packageList = append(packageList, basePackage, secondBuild)
|
||||
}
|
||||
|
||||
sort.Slice(packageList, func(i, j int) bool {
|
||||
return packageList[i].Name < packageList[j].Name
|
||||
})
|
||||
|
||||
return packageList
|
||||
}
|
||||
|
||||
var basePackageList = fetchPackageList{
|
||||
generatePackageList(),
|
||||
nil,
|
||||
func createBaseStoreFixture() *store.Store {
|
||||
var bName = "test"
|
||||
var b = blueprint.Blueprint{Name: bName, Version: "0.0.0"}
|
||||
|
||||
var date = time.Date(2019, 11, 27, 13, 19, 0, 0, time.FixedZone("UTC+1", 60*60))
|
||||
|
||||
s := store.New(nil)
|
||||
|
||||
s.Blueprints[bName] = b
|
||||
s.Composes = map[uuid.UUID]store.Compose{
|
||||
uuid.MustParse("e65f76f8-b0d9-4974-9dd7-745ae80b4721"): store.Compose{
|
||||
QueueStatus: "WAITING",
|
||||
Blueprint: &b,
|
||||
OutputType: "tar",
|
||||
Targets: nil,
|
||||
JobCreated: date,
|
||||
},
|
||||
uuid.MustParse("e65f76f8-b0d9-4974-9dd7-745ae80b4722"): store.Compose{
|
||||
QueueStatus: "RUNNING",
|
||||
Blueprint: &b,
|
||||
OutputType: "tar",
|
||||
Targets: nil,
|
||||
JobCreated: date,
|
||||
JobStarted: date,
|
||||
},
|
||||
uuid.MustParse("e65f76f8-b0d9-4974-9dd7-745ae80b4723"): store.Compose{
|
||||
QueueStatus: "FINISHED",
|
||||
Blueprint: &b,
|
||||
OutputType: "tar",
|
||||
Targets: nil,
|
||||
JobCreated: date,
|
||||
JobStarted: date,
|
||||
JobFinished: date,
|
||||
},
|
||||
uuid.MustParse("e65f76f8-b0d9-4974-9dd7-745ae80b4724"): store.Compose{
|
||||
QueueStatus: "FAILED",
|
||||
Blueprint: &b,
|
||||
OutputType: "tar",
|
||||
Targets: nil,
|
||||
JobCreated: date,
|
||||
JobStarted: date,
|
||||
JobFinished: date,
|
||||
},
|
||||
}
|
||||
|
||||
var BaseFixture = Fixture{
|
||||
basePackageList,
|
||||
return s
|
||||
}
|
||||
|
||||
func BaseFixture() Fixture {
|
||||
return Fixture{
|
||||
fetchPackageList{
|
||||
generatePackageList(),
|
||||
nil,
|
||||
},
|
||||
depsolve{
|
||||
[]rpmmd.PackageSpec{
|
||||
{
|
||||
|
|
@ -66,10 +123,16 @@ var BaseFixture = Fixture{
|
|||
},
|
||||
nil,
|
||||
},
|
||||
createBaseStoreFixture(),
|
||||
}
|
||||
}
|
||||
|
||||
var NonExistingPackage = Fixture{
|
||||
basePackageList,
|
||||
func NonExistingPackage() Fixture {
|
||||
return Fixture{
|
||||
fetchPackageList{
|
||||
generatePackageList(),
|
||||
nil,
|
||||
},
|
||||
depsolve{
|
||||
nil,
|
||||
&rpmmd.DNFError{
|
||||
|
|
@ -77,10 +140,16 @@ var NonExistingPackage = Fixture{
|
|||
Reason: "Error occurred when marking packages for installation: Problems in request:\nmissing packages: fash",
|
||||
},
|
||||
},
|
||||
createBaseStoreFixture(),
|
||||
}
|
||||
}
|
||||
|
||||
var BadDepsolve = Fixture{
|
||||
basePackageList,
|
||||
func BadDepsolve() Fixture {
|
||||
return Fixture{
|
||||
fetchPackageList{
|
||||
generatePackageList(),
|
||||
nil,
|
||||
},
|
||||
depsolve{
|
||||
nil,
|
||||
&rpmmd.DNFError{
|
||||
|
|
@ -88,9 +157,12 @@ var BadDepsolve = Fixture{
|
|||
Reason: "There was a problem depsolving ['go2rpm']: \n Problem: conflicting requests\n - nothing provides askalono-cli needed by go2rpm-1-4.fc31.noarch",
|
||||
},
|
||||
},
|
||||
createBaseStoreFixture(),
|
||||
}
|
||||
}
|
||||
|
||||
var BadFetch = Fixture{
|
||||
func BadFetch() Fixture {
|
||||
return Fixture{
|
||||
fetchPackageList{
|
||||
ret: nil,
|
||||
err: &rpmmd.DNFError{
|
||||
|
|
@ -105,4 +177,6 @@ var BadFetch = Fixture{
|
|||
Reason: "There was a problem depsolving ['go2rpm']: \n Problem: conflicting requests\n - nothing provides askalono-cli needed by go2rpm-1-4.fc31.noarch",
|
||||
},
|
||||
},
|
||||
createBaseStoreFixture(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package rpmmd_mock
|
||||
|
||||
import "github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
import (
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/store"
|
||||
)
|
||||
|
||||
type fetchPackageList struct {
|
||||
ret rpmmd.PackageList
|
||||
|
|
@ -14,6 +17,7 @@ type depsolve struct {
|
|||
type Fixture struct {
|
||||
fetchPackageList
|
||||
depsolve
|
||||
*store.Store
|
||||
}
|
||||
|
||||
type rpmmdMock struct {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue