Skip to content

Commit

Permalink
Added tests to ensure that variables can be set for 1st level mod dep…
Browse files Browse the repository at this point in the history
…endency.
  • Loading branch information
vhadianto committed Aug 23, 2024
1 parent 8e2b583 commit 6194045
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 13 deletions.
8 changes: 8 additions & 0 deletions tests/flowpipe_mod_tests/flowpipe_mod_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,14 @@ func (suite *FlowpipeModTestSuite) TestModVariable() {
intervalSchedule := reportTriggersWithIntervalVarWithDefaultValue.Config.(*modconfig.TriggerSchedule)
assert.Equal("weekly", intervalSchedule.Schedule)

modDependBPipelineEchoB := pipelines["mod_depend_b.pipeline.echo_b"]
if modDependBPipelineEchoB == nil {
assert.Fail("echo_b pipeline not found")
return
}

// The default value is 300 but we override it in the parent's pvars file to 42
assert.Equal("description from variable 42", *modDependBPipelineEchoB.Description)
}

func (suite *FlowpipeModTestSuite) TestModMessageStep() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
mod "mod_depend_a" {
title = "Child mod A"
}

pipeline "echo_one_depend_a" {
step "transform" "echo_one" {
value = "Hello World from Depend A"
}

output "val" {
value = step.transform.echo_one.value
}
}

pipeline "with_github_creds" {
param "creds" {
type = string
}
}

pipeline "http" {
description = "Bad HTTP step, just one step in the pipeline."

step "http" "my_step_1" {
url = "https://www.google.coms"
}

output "http" {
value = step.http.my_step_1.response_body
}
}


trigger "schedule" "http_step_trigger_in_a" {
schedule = "* * * * *"

enabled = false

pipeline = pipeline.http
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
mod "mod_depend_a_1" {
title = "Child mod A.1"
}


pipeline "http" {
description = "Bad HTTP step, just one step in the pipeline."

step "http" "my_step_1" {
url = "https://www.google.coms"
}

output "http" {
value = step.http.my_step_1.response_body
}
}


trigger "schedule" "http_step_trigger_in_a1" {
schedule = "* * * * *"

enabled = false

pipeline = pipeline.http
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod "mod_depend_b" {
title = "Child mod B"
}

pipeline "echo_b" {
description = "description from variable ${var.var_b_number}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "var_b_number" {
type = number
default = 300
}
24 changes: 24 additions & 0 deletions tests/flowpipe_mod_tests/mod_variable/.mod.cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"mod_depend_a@v1.0.0": {
"mod_depend_a_1": {
"version": "1.0.0",
"name": "mod_depend_a_1",
"struct_version": 20240429,
"alias": "mod_depend_a_1"
}
},
"test_mod": {
"mod_depend_a": {
"version": "1.0.0",
"name": "mod_depend_a",
"struct_version": 20240429,
"alias": "mod_depend_a"
},
"mod_depend_b": {
"version": "1.0.0",
"name": "mod_depend_b",
"struct_version": 20240429,
"alias": "mod_depend_b"
}
}
}
5 changes: 4 additions & 1 deletion tests/flowpipe_mod_tests/mod_variable/flowpipe.fpvars
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

var_two = "value from var file"
var_three = "var_three from var file"

var_three = "var_three from var file"

mod_depend_b.var_b_number = 42
21 changes: 21 additions & 0 deletions tests/flowpipe_mod_tests/mod_variable/mod.fp
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
mod "test_mod" {
title = "my_mod"

require {
mod "mod_depend_a" {
version = "1.0.0"
}
mod "mod_depend_b" {
version = "1.0.0"
}
}
}

variable "schedule_default" {
Expand Down Expand Up @@ -153,6 +162,18 @@ pipeline "github_get_issue_with_number" {
}
}

pipeline "description_from_var_two" {
description = "description from variable: ${var.var_two}"
}

pipeline "description_from_var_four" {
description = "description from variable: ${var.var_four}"
}

pipeline "foo-bar" {
description = "description from variable: ${var.var_four}"
}

locals {
locals_three_merge = merge(local.locals_three, {
key_three = 33
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,9 @@ pipeline "with_github_creds" {
type = string
}

step "transform" "creds" {
value = credential.github[param.creds].token
}

step "transform" "merge_creds" {
value = merge(credential.github[param.creds], {cred_name = param.creds})
}

output "val" {
value = step.transform.creds.value
}

output "val_merge" {
value = step.transform.merge_creds.value
}
}


Expand Down

0 comments on commit 6194045

Please sign in to comment.