Skip to content

Commit

Permalink
add multiple deployer test
Browse files Browse the repository at this point in the history
  • Loading branch information
mfleader committed Oct 27, 2023
1 parent c09b7ba commit b136c2a
Showing 1 changed file with 70 additions and 22 deletions.
92 changes: 70 additions & 22 deletions internal/step/plugin/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,60 @@ func (s *stageChangeHandler) OnStepComplete(
s.message <- message
}

func TestProvider_MultipleDeployers(t *testing.T) {
logger := log.New(
log.Config{
Level: log.LevelError,
Destination: log.DestinationStdout,
},
)
deployerRegistry := deployer_registry.New(
deployer.Any(testdeployer.NewFactory()))
deployTimeMs := 20
workflowDeployerCfg := map[string]any{
"image": map[string]any{
"type": "test-impl",
"deploy_time": deployTimeMs,
"deploy_succeed": true,
},
"python": map[string]any{"type": "test-impl"},
}

plp, err := plugin.New(
logger,
deployerRegistry,
workflowDeployerCfg,
)
assert.NoError(t, err)
assert.Equals(t, plp.Kind(), "plugin")
assert.NotNil(t, plp.ProviderSchema())
assert.NotNil(t, plp.RunProperties())
assert.NotNil(t, plp.Lifecycle())

stepSchema := map[string]any{
"plugin": map[string]string{
"src": "simulation",
"type": "image",
},
}
byteSchema := map[string][]byte{}

runnable, err := plp.LoadSchema(stepSchema, byteSchema)
assert.NoError(t, err)

assert.NotNil(t, runnable.RunSchema())

_, err = runnable.Lifecycle(map[string]any{"step": "wait"})
assert.NoError(t, err)

_, err = runnable.Lifecycle(map[string]any{"step": "hello"})
assert.NoError(t, err)

// There is more than one step, so no specified one will cause an error.
_, err = runnable.Lifecycle(map[string]any{"step": nil})
assert.Error(t, err)
}

func TestProvider_Utility(t *testing.T) {
workflowDeployerCfg := map[string]any{
"image": map[string]any{"type": "test-impl"},
Expand Down Expand Up @@ -326,30 +380,21 @@ func TestProvider_VerifyCancelSignal(t *testing.T) {
}

func TestProvider_DeployFail(t *testing.T) {
logConfig := log.Config{
Level: log.LevelError,
Destination: log.DestinationStdout,
}
logger := log.New(
logConfig,
log.Config{
Level: log.LevelError,
Destination: log.DestinationStdout,
},
)

deployerRegistry := deployer_registry.New(
deployer.Any(testdeployer.NewFactory()))
deployTimeMs := 20
//workflowDeployerCfg := map[string]any{
// "type": "test-impl",
// "deploy_time": deployTimeMs,
// "deploy_succeed": true,
//}

workflowDeployerCfg := map[string]any{
"image": map[string]any{"type": "test-impl"},
//"deploy_time": deployTimeMs,
//"deploy_succeed": true,
"image": map[string]any{"type": "test-impl"},
"deploy_time": deployTimeMs,
"deploy_succeed": true,
}

deployerRegistry := deployer_registry.New(
deployer.Any(testdeployer.NewFactory()))

plp, err := plugin.New(
logger,
deployerRegistry,
Expand Down Expand Up @@ -377,10 +422,13 @@ func TestProvider_DeployFail(t *testing.T) {

assert.NoError(t, running.ProvideStageInput(
string(plugin.StageIDDeploy),
map[string]any{"deploy": map[string]any{
"type": "test-impl",
"deploy_succeed": false,
"deploy_time": deployTimeMs}},
map[string]any{
"deploy": map[string]any{
"type": "test-impl",
//"deploy_succeed": false,
//"deploy_time": deployTimeMs,
},
},
))

waitTimeMs := 50
Expand Down

0 comments on commit b136c2a

Please sign in to comment.