Files
odo/pkg/libdevfile/command_apply_test.go
Philippe Martin 9a239c4e77 Use a single handler for executing all commands (#6826)
* Document current implementations of command handlers

* Add unit tests for execHAndler

* Refactor pkg/devfile/image to inject Backend as dependency

* Use same handler for kubedev/podmandev

* Fail after SelectBackend==nil only if backend is needed

* Move runHandler to dev/common

* Unit tests for runHandler

* Create a component.ExecuteTerminatingCommand

* ExecuteTerminatingCommand/ExecuteNonTerminatingCommand for Handler

* Fix calling other command types

* Consider parent group to determine if a command is terminating

* Replace component.execHandler by common.runHandler

* Remove execHandler

* Make runHandler and most of fields private and pass containersRunning to handler

* Pass containersRunning value

* deploy using common Handler

* Fix tests

* Use specific Dev/Deploy mode for Apply

* Fix cmdline for job

* Fix unit tests

* Pass appName and componentName with ctx to handler

* Move handler to pkg/component package

* Update doc

* Unit tests Deploy

* Unit tests Build

* Unit tests Run

* Unit tests PostStart

* Unit tests PreStop

* Update doc

* Fix Podman tests

* Fix hotReload on podman

* Change podman version timeout to 30s for tests

* Cleanup + fix doc
2023-05-26 11:01:21 -04:00

68 lines
1.7 KiB
Go

package libdevfile
import (
"context"
"testing"
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/v2/pkg/devfile/parser"
"github.com/devfile/library/v2/pkg/devfile/parser/data"
"github.com/redhat-developer/odo/pkg/libdevfile/generator"
)
func Test_applyCommand_Execute(t *testing.T) {
command1 := generator.GetApplyCommand(generator.ApplyCommandParams{
Id: "command1",
Component: "component",
})
component := generator.GetContainerComponent(generator.ContainerComponentParams{
Name: "component",
})
component1 := generator.GetContainerComponent(generator.ContainerComponentParams{
Name: "component1",
})
component2 := generator.GetContainerComponent(generator.ContainerComponentParams{
Name: "component2",
})
type fields struct {
command v1alpha2.Command
devfileObj func() parser.DevfileObj
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{
name: "execute an apply command",
fields: fields{
command: command1,
devfileObj: func() parser.DevfileObj {
data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
_ = data.AddCommands([]v1alpha2.Command{command1})
_ = data.AddComponents([]v1alpha2.Component{component, component1, component2})
return parser.DevfileObj{
Data: data,
}
},
},
},
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := &applyCommand{
command: tt.fields.command,
devfileObj: tt.fields.devfileObj(),
}
// TODO handler
if err := o.Execute(context.Background(), nil, nil); (err != nil) != tt.wantErr {
t.Errorf("applyCommand.Execute() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}