compose: refactor compose related structure into its own package
The store package is getting too big and convoluted, this new package will help with separation of the compose logic from our current implementation of the store. The current implementation will be removed in following commits.
This commit is contained in:
parent
62d186cd1b
commit
eb6c0f6fce
2 changed files with 297 additions and 0 deletions
125
internal/compose/compose_test.go
Normal file
125
internal/compose/compose_test.go
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
package compose
|
||||
|
||||
import (
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetState(t *testing.T) {
|
||||
cases := []struct{
|
||||
compose Compose
|
||||
expecedStatus common.ComposeState
|
||||
}{
|
||||
{
|
||||
compose: Compose{
|
||||
ImageBuilds: []ImageBuild{
|
||||
{QueueStatus: common.IBWaiting},
|
||||
},
|
||||
},
|
||||
expecedStatus: common.CWaiting,
|
||||
},
|
||||
{
|
||||
compose: Compose{
|
||||
ImageBuilds: []ImageBuild{
|
||||
{QueueStatus: common.IBRunning},
|
||||
},
|
||||
},
|
||||
expecedStatus: common.CRunning,
|
||||
},
|
||||
{
|
||||
compose: Compose{
|
||||
ImageBuilds: []ImageBuild{
|
||||
{QueueStatus: common.IBFailed},
|
||||
},
|
||||
},
|
||||
expecedStatus: common.CFailed,
|
||||
},
|
||||
{
|
||||
compose: Compose{
|
||||
ImageBuilds: []ImageBuild{
|
||||
{QueueStatus: common.IBFinished},
|
||||
},
|
||||
},
|
||||
expecedStatus: common.CFinished,
|
||||
},
|
||||
{
|
||||
compose: Compose{
|
||||
ImageBuilds: []ImageBuild{
|
||||
{QueueStatus: common.IBWaiting},
|
||||
{QueueStatus: common.IBWaiting},
|
||||
},
|
||||
},
|
||||
expecedStatus: common.CWaiting,
|
||||
},
|
||||
{
|
||||
compose: Compose{
|
||||
ImageBuilds: []ImageBuild{
|
||||
{QueueStatus: common.IBWaiting},
|
||||
{QueueStatus: common.IBRunning},
|
||||
},
|
||||
},
|
||||
expecedStatus: common.CRunning,
|
||||
},
|
||||
{
|
||||
compose: Compose{
|
||||
ImageBuilds: []ImageBuild{
|
||||
{QueueStatus: common.IBRunning},
|
||||
{QueueStatus: common.IBRunning},
|
||||
},
|
||||
},
|
||||
expecedStatus: common.CRunning,
|
||||
},
|
||||
{
|
||||
compose: Compose{
|
||||
ImageBuilds: []ImageBuild{
|
||||
{QueueStatus: common.IBRunning},
|
||||
{QueueStatus: common.IBFailed},
|
||||
},
|
||||
},
|
||||
expecedStatus: common.CRunning,
|
||||
},
|
||||
{
|
||||
compose: Compose{
|
||||
ImageBuilds: []ImageBuild{
|
||||
{QueueStatus: common.IBWaiting},
|
||||
{QueueStatus: common.IBFailed},
|
||||
},
|
||||
},
|
||||
expecedStatus: common.CRunning,
|
||||
},
|
||||
{
|
||||
compose: Compose{
|
||||
ImageBuilds: []ImageBuild{
|
||||
{QueueStatus: common.IBFailed},
|
||||
{QueueStatus: common.IBFailed},
|
||||
},
|
||||
},
|
||||
expecedStatus: common.CFailed,
|
||||
},
|
||||
{
|
||||
compose: Compose{
|
||||
ImageBuilds: []ImageBuild{
|
||||
{QueueStatus: common.IBFinished},
|
||||
{QueueStatus: common.IBFinished},
|
||||
},
|
||||
},
|
||||
expecedStatus: common.CFinished,
|
||||
},
|
||||
{
|
||||
compose: Compose{
|
||||
ImageBuilds: []ImageBuild{
|
||||
{QueueStatus: common.IBFinished},
|
||||
{QueueStatus: common.IBFailed},
|
||||
},
|
||||
},
|
||||
expecedStatus: common.CFailed,
|
||||
},
|
||||
}
|
||||
for n, c := range cases {
|
||||
got := c.compose.GetState()
|
||||
wanted := c.expecedStatus
|
||||
if got != wanted {
|
||||
t.Error("Compose", n, "should be in", wanted.ToString(), "state, but it is:", got.ToString())
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue