Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentganne committed Jan 28, 2020
1 parent 9484bd5 commit b1d82ce
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 26 deletions.
24 changes: 0 additions & 24 deletions deployments/testdata/test_input_types.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions tasks/workflow/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func TestRunConsulWorkflowPackageTests(t *testing.T) {
t.Run("testDispatcherRun", func(t *testing.T) {
testDispatcherRun(t, srv, client)
})
t.Run("testWorkflowInputs", func(t *testing.T) {
testWorkflowInputs(t, srv, client)
})
})

populateKV(t, srv)
Expand Down
34 changes: 34 additions & 0 deletions tasks/workflow/testdata/test_input_types.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
tosca_definitions_version: alien_dsl_2_0_0

metadata:
template_name: org.ystia.yorc.samples.Greetings
template_version: 1.0.0-SNAPSHOT
template_author: yorc


node_types:
org.ystia.yorc.samples.GreetingsComponentType:
description: "Sample component having an operation needing an input"
derived_from: tosca.nodes.SoftwareComponent
interfaces:
custom:
inputs:
greetings_user:
type: string
say_goodbye:
implementation:
type: ystia.yorc.tests.artifacts.Implementation.Custom
file: say_goodbye
say_hello:
implementation:
type: ystia.yorc.tests.artifacts.Implementation.Custom
file: say_hello
Standard:
start:
implementation:
type: ystia.yorc.tests.artifacts.Implementation.Custom
file: start
create:
implementation:
type: ystia.yorc.tests.artifacts.Implementation.Custom
file: create
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ topology_template:
inputs:
greetings_user: {get_input: user}
say_goodbye:
implementation: scripts/goodbye.sh
implementation:
type: ystia.yorc.tests.artifacts.Implementation.Custom
file: say_goodbye
say_hello:
implementation: scripts/hello.sh
implementation:
type: ystia.yorc.tests.artifacts.Implementation.Custom
file: say_hello
requirements:
- hostedOnVirtualMachineHost:
type_requirement: host
Expand Down
32 changes: 32 additions & 0 deletions tasks/workflow/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/testutil"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ystia/yorc/v4/config"
Expand Down Expand Up @@ -194,3 +195,34 @@ func testRegisterInlineWorkflow(t *testing.T, srv1 *testutil.TestServer, cc *api
require.NoError(t, err, "Unexpected error building workflow for %s", topologyPath)

}

func testWorkflowInputs(t *testing.T, srv1 *testutil.TestServer, cc *api.Client) {
deploymentID := strings.Replace(t.Name(), "/", "_", -1)
err := deployments.StoreDeploymentDefinition(context.Background(), deploymentID, "testdata/test_topo_workflow_inputs.yaml")
require.NoError(t, err, "Failed to store deployment definition")

mockExecutor := &mockExecutor{}
registry.GetRegistry().RegisterDelegates([]string{"org.ystia.yorc.samples.GreetingsComponentType"}, mockExecutor, "tests")
registry.GetRegistry().RegisterOperationExecutor([]string{"ystia.yorc.tests.artifacts.Implementation.Custom"}, mockExecutor, "tests")

workflowName := "greet"
stepName := "GreetingsComponent_say_hello"
wfSteps, err := builder.BuildWorkFlow(context.Background(), deploymentID, workflowName)
require.NoError(t, err, "Failed to build workflow %s", workflowName)
bs := wfSteps[stepName]
require.NotNil(t, bs, "Failed to find step %s in workflow %s", stepName, workflowName)

bs.Next = nil
te := &taskExecution{id: "taskExecutionID", taskID: "taskID", targetID: deploymentID}
s := wrapBuilderStep(bs, cc, te)
srv1.SetKV(t, path.Join(consulutil.WorkflowsPrefix, s.t.taskID, "GreetingsComponent_say_hello"), []byte("initial"))

mockExecutor.callOpsCalled = false
mockExecutor.errorsCallOps = false
mockExecutor.delegateCalled = false
mockExecutor.errorsDelegate = false
err = s.run(context.Background(), config.Configuration{}, deploymentID, false, workflowName, &worker{})
require.NoError(t, err, "Failed running step %s in workflow %s", stepName, workflowName)

assert.Equal(t, true, mockExecutor.callOpsCalled, "Expected an opreation to be called running step %s", stepName)
}

0 comments on commit b1d82ce

Please sign in to comment.