From e976c68ccec0b21ee367918cf800cf04ef41446d Mon Sep 17 00:00:00 2001 From: Matt Leader Date: Tue, 21 Nov 2023 17:00:38 -0500 Subject: [PATCH] Test Deployer Mismatch (#130) * add test * remove redundant tests * change stub deployment type * update deployer double dep --- go.mod | 2 +- go.sum | 6 +- internal/step/plugin/provider_test.go | 94 ++++++--------------------- 3 files changed, 22 insertions(+), 80 deletions(-) diff --git a/go.mod b/go.mod index 1f667f2d..fe72af32 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 65b6ca80..2147b255 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/step/plugin/provider_test.go b/internal/step/plugin/provider_test.go index 6858b002..e695355f 100644 --- a/internal/step/plugin/provider_test.go +++ b/internal/step/plugin/provider_test.go @@ -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" ) @@ -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{ @@ -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{ @@ -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) @@ -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),