-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated Flowpipe parsing automated test from Flowpipe repo.
- Loading branch information
Showing
52 changed files
with
3,100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package pipeline_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/turbot/pipe-fittings/misc" | ||
) | ||
|
||
func TestAllParam(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
pipelines, _, err := misc.LoadPipelines(context.TODO(), "./pipelines/all_param.fp") | ||
assert.Nil(err, "error found") | ||
|
||
pipeline := pipelines["local.pipeline.all_param"] | ||
if pipeline == nil { | ||
assert.Fail("Pipeline not found") | ||
return | ||
} | ||
|
||
// all steps must have unresolved attributes | ||
for _, step := range pipeline.Steps { | ||
// except echo bazz | ||
if step.GetName() == "echo_baz" { | ||
assert.Nil(step.GetUnresolvedAttributes()["text"]) | ||
} else { | ||
assert.NotNil(step.GetUnresolvedAttributes()["text"]) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package pipeline_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hashicorp/hcl/v2" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/turbot/pipe-fittings/misc" | ||
"github.com/turbot/pipe-fittings/modconfig" | ||
) | ||
|
||
func TestApproval(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
mod, err := misc.LoadPipelinesReturningItsMod(context.TODO(), "./pipelines/approval.fp") | ||
assert.Nil(err) | ||
assert.NotNil(mod) | ||
|
||
assert.Equal(3, len(mod.ResourceMaps.Integrations)) | ||
|
||
integration := mod.ResourceMaps.Integrations["local.integration.slack.my_slack_app"] | ||
if integration == nil { | ||
assert.Fail("Integration not found") | ||
return | ||
} | ||
|
||
assert.Equal("local.integration.slack.my_slack_app", integration.Name()) | ||
assert.Equal("slack", integration.(*modconfig.SlackIntegration).Type) | ||
assert.Equal("xoxp-111111", *integration.(*modconfig.SlackIntegration).Token) | ||
assert.Equal("Q#$$#@#$$#W", *integration.(*modconfig.SlackIntegration).SigningSecret) | ||
|
||
integration = mod.ResourceMaps.Integrations["local.integration.email.email_integration"] | ||
if integration == nil { | ||
assert.Fail("Integration not found") | ||
return | ||
} | ||
|
||
assert.Equal("local.integration.email.email_integration", integration.Name()) | ||
assert.Equal("email", integration.(*modconfig.EmailIntegration).Type) | ||
assert.Equal("foo bar baz", *integration.(*modconfig.EmailIntegration).SmtpHost) | ||
assert.Equal("bar foo baz", *integration.(*modconfig.EmailIntegration).DefaultSubject) | ||
|
||
pipeline := mod.ResourceMaps.Pipelines["local.pipeline.approval"] | ||
if pipeline == nil { | ||
assert.Fail("Pipeline not found") | ||
return | ||
} | ||
|
||
inputStep, ok := pipeline.Steps[0].(*modconfig.PipelineStepInput) | ||
if !ok { | ||
assert.Fail("Pipeline step not found") | ||
return | ||
} | ||
|
||
assert.Equal("input", inputStep.Name) | ||
assert.NotNil(inputStep.Notify) | ||
assert.Equal("foo", *inputStep.Notify.Channel) | ||
|
||
integrationLink := inputStep.Notify.Integration | ||
assert.NotNil(integrationLink) | ||
integrationMap := integrationLink.AsValueMap() | ||
assert.NotNil(integrationMap) | ||
assert.Equal("xoxp-111111", integrationMap["token"].AsString()) | ||
|
||
assert.Equal("remove this after integrated", *inputStep.Token) | ||
|
||
inputsAfterEval, err := inputStep.GetInputs(&hcl.EvalContext{}) | ||
// the notify should override the inline definition (the inline definition should not be there after integrated 2023) | ||
assert.Nil(err) | ||
|
||
assert.Equal("xoxp-111111", inputsAfterEval["token"].(string)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package pipeline_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/turbot/pipe-fittings/misc" | ||
) | ||
|
||
func TestChildPipeline(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
pipelines, _, err := misc.LoadPipelines(context.TODO(), "./pipelines/child_pipeline.fp") | ||
assert.Nil(err, "error found") | ||
|
||
assert.GreaterOrEqual(len(pipelines), 1, "wrong number of pipelines") | ||
|
||
if pipelines["local.pipeline.parent"] == nil { | ||
assert.Fail("parent pipeline not found") | ||
return | ||
} | ||
|
||
childPipelineStep := pipelines["local.pipeline.parent"].GetStep("pipeline.child_pipeline") | ||
if childPipelineStep == nil { | ||
assert.Fail("pipeline.child_pipeline step not found") | ||
return | ||
} | ||
|
||
dependsOn := childPipelineStep.GetDependsOn() | ||
assert.Equal(len(dependsOn), 0) | ||
|
||
// Unresolved attributes should be null at this stage, we have fully parsed child_pipeline.fp | ||
unresolvedAttributes := childPipelineStep.GetUnresolvedAttributes() | ||
assert.Equal(0, len(unresolvedAttributes)) | ||
} | ||
|
||
func TestChildPipelineWithArgs(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
pipelines, _, err := misc.LoadPipelines(context.TODO(), "./pipelines/child_pipeline.fp") | ||
assert.Nil(err, "error found") | ||
|
||
assert.GreaterOrEqual(len(pipelines), 1, "wrong number of pipelines") | ||
|
||
if pipelines["local.pipeline.child_step_with_args"] == nil { | ||
assert.Fail("child_step_with_args pipeline not found") | ||
return | ||
} | ||
|
||
childPipelineStep := pipelines["local.pipeline.child_step_with_args"].GetStep("pipeline.child_pipeline") | ||
if childPipelineStep == nil { | ||
assert.Fail("pipeline.child_pipeline step not found") | ||
return | ||
} | ||
|
||
dependsOn := childPipelineStep.GetDependsOn() | ||
assert.Equal(len(dependsOn), 0) | ||
|
||
// We have fully parsed the file, we should not have unresolved attributes | ||
unresolvedAttributes := childPipelineStep.GetUnresolvedAttributes() | ||
assert.Equal(0, len(unresolvedAttributes)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package pipeline_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/turbot/pipe-fittings/misc" | ||
) | ||
|
||
func TestDemoPipeline(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
ctx := context.Background() | ||
|
||
pipelines, _, err := misc.LoadPipelines(ctx, "./pipelines/demo.fp") | ||
assert.Nil(err, "error found") | ||
assert.NotNil(pipelines) | ||
assert.NotNil(pipelines["local.pipeline.complex_one"]) | ||
|
||
// TODO: check pipeline definition | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package pipeline_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/turbot/pipe-fittings/misc" | ||
) | ||
|
||
func TestImplicitDependsIndex(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
pipelines, _, err := misc.LoadPipelines(context.TODO(), "./pipelines/depends.fp") | ||
assert.Nil(err, "error found") | ||
|
||
assert.GreaterOrEqual(len(pipelines), 1, "wrong number of pipelines") | ||
|
||
if pipelines["local.pipeline.depends_index"] == nil { | ||
assert.Fail("depends_index pipeline not found") | ||
return | ||
} | ||
|
||
step := pipelines["local.pipeline.depends_index"].GetStep("echo.echo_1") | ||
if step == nil { | ||
assert.Fail("echo.echo_1 step not found") | ||
return | ||
} | ||
|
||
dependsOn := step.GetDependsOn() | ||
assert.Contains(dependsOn, "sleep.sleep_1") | ||
} | ||
|
||
func TestImplicitDepends(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
pipelines, _, err := misc.LoadPipelines(context.TODO(), "./pipelines/depends.fp") | ||
assert.Nil(err, "error found") | ||
|
||
assert.GreaterOrEqual(len(pipelines), 1, "wrong number of pipelines") | ||
|
||
if pipelines["local.pipeline.implicit_depends"] == nil { | ||
assert.Fail("implicit_depends pipeline not found") | ||
return | ||
} | ||
|
||
step := pipelines["local.pipeline.implicit_depends"].GetStep("sleep.sleep_2") | ||
if step == nil { | ||
assert.Fail("sleep.sleep_2 step not found") | ||
return | ||
} | ||
|
||
dependsOn := step.GetDependsOn() | ||
assert.Contains(dependsOn, "sleep.sleep_1") | ||
} | ||
|
||
func TestExplicitDependsOnIndex(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
pipelines, _, err := misc.LoadPipelines(context.TODO(), "./pipelines/depends.fp") | ||
assert.Nil(err, "error found") | ||
|
||
assert.GreaterOrEqual(len(pipelines), 1, "wrong number of pipelines") | ||
|
||
if pipelines["local.pipeline.explicit_depends_index"] == nil { | ||
assert.Fail("explicit_depends_index pipeline not found") | ||
return | ||
} | ||
|
||
step := pipelines["local.pipeline.explicit_depends_index"].GetStep("echo.echo_1") | ||
if step == nil { | ||
assert.Fail("echo.echo_1 step not found") | ||
return | ||
} | ||
|
||
dependsOn := step.GetDependsOn() | ||
assert.Contains(dependsOn, "sleep.sleep_1") | ||
} | ||
|
||
func TestImplicitQueryDepends(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
pipelines, _, err := misc.LoadPipelines(context.TODO(), "./pipelines/depends.fp") | ||
assert.Nil(err, "error found") | ||
|
||
assert.GreaterOrEqual(len(pipelines), 1, "wrong number of pipelines") | ||
|
||
if pipelines["local.pipeline.query"] == nil { | ||
assert.Fail("query pipeline not found") | ||
return | ||
} | ||
|
||
step := pipelines["local.pipeline.query"].GetStep("echo.result") | ||
if step == nil { | ||
assert.Fail("echo.result step not found") | ||
return | ||
} | ||
|
||
dependsOn := step.GetDependsOn() | ||
assert.Contains(dependsOn, "query.query_1") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package pipeline_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/turbot/pipe-fittings/misc" | ||
) | ||
|
||
func TestDoUntil(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
pipelines, _, err := misc.LoadPipelines(context.TODO(), "./pipelines/do_until.fp") | ||
assert.Nil(err, "error found") | ||
|
||
assert.GreaterOrEqual(len(pipelines), 1, "wrong number of pipelines") | ||
|
||
if pipelines["local.pipeline.do_until"] == nil { | ||
assert.Fail("do_until pipeline not found") | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package pipeline_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/turbot/pipe-fittings/misc" | ||
) | ||
|
||
func TestStepErrorConfig(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
pipelines, _, err := misc.LoadPipelines(context.TODO(), "./pipelines/error.fp") | ||
assert.Nil(err, "error found") | ||
|
||
assert.GreaterOrEqual(len(pipelines), 1, "wrong number of pipelines") | ||
|
||
if pipelines["local.pipeline.bad_http"] == nil { | ||
assert.Fail("bad_http pipeline not found") | ||
return | ||
} | ||
|
||
} | ||
|
||
func TestStepErrorConfigRetries(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
pipelines, _, err := misc.LoadPipelines(context.TODO(), "./pipelines/error.fp") | ||
assert.Nil(err, "error found") | ||
|
||
assert.GreaterOrEqual(len(pipelines), 1, "wrong number of pipelines") | ||
|
||
if pipelines["local.pipeline.bad_http_retries"] == nil { | ||
assert.Fail("bad_http_retries pipeline not found") | ||
return | ||
} | ||
|
||
step := pipelines["local.pipeline.bad_http_retries"].GetStep("http.my_step_1") | ||
|
||
if step == nil { | ||
assert.Fail("step not found") | ||
return | ||
} | ||
|
||
errorConfig := step.GetErrorConfig() | ||
if step == nil { | ||
assert.Fail("error config not found") | ||
return | ||
} | ||
|
||
assert.Equal(2, errorConfig.Retries) | ||
} |
Oops, something went wrong.