Skip to content

Commit

Permalink
Test Deployer Mismatch (#130)
Browse files Browse the repository at this point in the history
* add test

* remove redundant tests

* change stub deployment type

* update deployer double dep
  • Loading branch information
mfleader committed Nov 21, 2023
1 parent e84e23c commit e976c68
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 80 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
go.flow.arcalot.io/pluginsdk v0.5.1
go.flow.arcalot.io/podmandeployer v0.7.0
go.flow.arcalot.io/pythondeployer v0.4.0
go.flow.arcalot.io/testdeployer v0.4.0
go.flow.arcalot.io/testdeployer v0.5.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,14 @@ go.flow.arcalot.io/kubernetesdeployer v0.8.0 h1:UjH/aspPif/k+X65sLWlNDZAW5JlzUfg
go.flow.arcalot.io/kubernetesdeployer v0.8.0/go.mod h1:BhERhKpvQMJkrcW9lbBF4kJEe+OGhz2NpSftZIgtVNQ=
go.flow.arcalot.io/pluginsdk v0.5.1 h1:ebb2ThAqmjmwGpDyKpd1wEDUisPqPabgARjFohy47Io=
go.flow.arcalot.io/pluginsdk v0.5.1/go.mod h1:2s2f//7uOkBjr1QaiWJD/bqDIeLlINJtD1BhiY4aGPM=
go.flow.arcalot.io/podmandeployer v0.6.1 h1:NPSQ82PyvxTRDsHuLj6oBhPUlhVVqPlnXWkElF2PcT8=
go.flow.arcalot.io/podmandeployer v0.6.1/go.mod h1:4wfcl0qjV02y64We3ZSDz+3lwdOfbe+gpFjm7SQKTRA=
go.flow.arcalot.io/podmandeployer v0.6.2 h1:iAAZGgwhxInEVAleakavGruHnW4qsD/v39JpfnTeXiE=
go.flow.arcalot.io/podmandeployer v0.6.2/go.mod h1:BmKbyG2qZG9PMPLkIeXUvKVJfU+AZx+POLvydZN26IY=
go.flow.arcalot.io/podmandeployer v0.7.0 h1:bXzWi4IjjLTIftUbH2NPgPiyTb82lzERVgfHP4zpmXI=
go.flow.arcalot.io/podmandeployer v0.7.0/go.mod h1:tiWVDNpeNpPrY2GloihwjtnCEzJf8zNxBbiwVGRX7rs=
go.flow.arcalot.io/pythondeployer v0.4.0 h1:l8nw6awYMVzgND+ZXdbnNJPYu3V0sgSUFsIzn+SRgh0=
go.flow.arcalot.io/pythondeployer v0.4.0/go.mod h1:me9SIMVTCBzCmceILdBMxXYrZGakiPOMasHgujmgJlE=
go.flow.arcalot.io/testdeployer v0.4.0 h1:helexgZOnYlbzU+egkxsLs95iMwE3lc+vp+Qbv2xwFI=
go.flow.arcalot.io/testdeployer v0.4.0/go.mod h1:Luw76oKeri40a7k8buk7Q7J86Tpt8lf9LTVZr6lqgTk=
go.flow.arcalot.io/testdeployer v0.5.0 h1:kS/nCQuqGNpkILG5QwtalE59mefuePdTaol95mSUMRQ=
go.flow.arcalot.io/testdeployer v0.5.0/go.mod h1:W8u5VACtmfto3yCYO1D/YQNsV8tivx4MaxehcXdsXGU=
go.flow.arcalot.io/testplugin v0.3.0 h1:LY0VWL1M0X+mSE0nVCwoD0PjQHqKhbka2Gc70uuP04k=
go.flow.arcalot.io/testplugin v0.3.0/go.mod h1:TW6h/kZyM+4gBBKqvoDI0XWXgNcUMKbDHaQOaKIRZdk=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
Expand Down
94 changes: 19 additions & 75 deletions internal/step/plugin/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"go.arcalot.io/log/v2"
"go.flow.arcalot.io/deployer"
deployer_registry "go.flow.arcalot.io/deployer/registry"
docker "go.flow.arcalot.io/dockerdeployer"
"go.flow.arcalot.io/engine/internal/step"
"go.flow.arcalot.io/engine/internal/step/plugin"
testdeployer "go.flow.arcalot.io/testdeployer"
stubdeployer "go.flow.arcalot.io/testdeployer/stub"
"sync"
"testing"
)
Expand Down Expand Up @@ -111,59 +111,6 @@ 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()),
deployer.Any(docker.NewFactory()))
deployTimeMs := 20
workflowDeployerCfg := map[string]any{
"builtin": map[string]any{
"deployer_name": "test-impl",
"deploy_time": deployTimeMs,
"deploy_succeed": true,
},
"image": map[string]any{
"deployer_name": "docker",
},
}

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]any{
"src": "simulation",
"deployment_type": "builtin",
},
}
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_MissingDeployer(t *testing.T) {
logger := log.New(
log.Config{
Expand All @@ -181,24 +128,6 @@ func TestProvider_MissingDeployer(t *testing.T) {
_, err := plugin.New(logger, deployerRegistry, workflowDeployerCfg)
assert.Error(t, err)
}
func TestProvider_MismatchedDeploymentTypes(t *testing.T) {
logger := log.New(
log.Config{
Level: log.LevelError,
Destination: log.DestinationStdout,
},
)
deployerRegistry := deployer_registry.New(deployer.Any(testdeployer.NewFactory()))
// Mismatched. test-impl is has the deployment type builtin, but we're trying to specify it for the image type.
workflowDeployerCfg := map[string]any{
"image": map[string]any{
"deployer_name": "test-impl",
},
}

_, err := plugin.New(logger, deployerRegistry, workflowDeployerCfg)
assert.Error(t, err)
}

func TestProvider_Utility(t *testing.T) {
workflowDeployerCfg := map[string]any{
Expand Down Expand Up @@ -252,20 +181,27 @@ func TestProvider_HappyError(t *testing.T) {
workflowDeployerCfg := map[string]any{
"builtin": map[string]any{
"deployer_name": "test-impl"},
"stubby": map[string]any{
"deployer_name": "test-stub",
},
}

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

// Deployer type not in deployer registry
_, err := plugin.New(logger, deployerRegistry, map[string]any{
"wrong": map[string]any{
"deployer_name": "test-impl",
}})
assert.Error(t, err)

// Deployment type stubby is in deployer registry, but does not
// match the deployment type for test-impl
_, err = plugin.New(logger, deployerRegistry, map[string]any{
"builtin": map[string]any{
"deployer_name": "bad",
"stubby": map[string]any{
"deployer_name": "test-impl",
}})
assert.Error(t, err)

Expand Down Expand Up @@ -298,6 +234,14 @@ func TestProvider_HappyError(t *testing.T) {
assert.Error(t, running.ProvideStageInput(
"", nil))

// deployer name and deployment type mismatch
assert.Error(t, running.ProvideStageInput(
string(plugin.StageIDDeploy),
map[string]any{"deploy": map[string]any{
"deployer_name": "test-stub",
"deploy_time": 1}},
))

// unserialize malformed deploy schema
assert.Error(t, running.ProvideStageInput(
string(plugin.StageIDDeploy),
Expand Down

0 comments on commit e976c68

Please sign in to comment.