Skip to content

Commit

Permalink
Fix conversion of job parameters (#744)
Browse files Browse the repository at this point in the history
## Changes

Another example of singular/plural conversion.

Longer term solution is we do a full sweep of the type using reflection
to make sure we cover all fields.

## Tests

Unit test passes.
  • Loading branch information
pietern authored Sep 7, 2023
1 parent 50b2c0b commit c0ebfb8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bundle/deploy/terraform/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func BundleToTerraform(config *config.Root) (*schema.Root, bool) {
Tag: git.GitTag,
}
}

for _, v := range src.Parameters {
var t schema.ResourceJobParameter
conv(v, &t)
dst.Parameter = append(dst.Parameter, t)
}
}

tfroot.Resource.Job[k] = &dst
Expand Down
13 changes: 13 additions & 0 deletions bundle/deploy/terraform/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ func TestConvertJob(t *testing.T) {
GitProvider: jobs.GitProviderGitHub,
GitUrl: "https://github.com/foo/bar",
},
Parameters: []jobs.JobParameterDefinition{
{
Name: "param1",
Default: "default1",
},
{
Name: "param2",
Default: "default2",
},
},
},
}

Expand All @@ -44,6 +54,9 @@ func TestConvertJob(t *testing.T) {
assert.Equal(t, "my job", out.Resource.Job["my_job"].Name)
assert.Len(t, out.Resource.Job["my_job"].JobCluster, 1)
assert.Equal(t, "https://github.com/foo/bar", out.Resource.Job["my_job"].GitSource.Url)
assert.Len(t, out.Resource.Job["my_job"].Parameter, 2)
assert.Equal(t, "param1", out.Resource.Job["my_job"].Parameter[0].Name)
assert.Equal(t, "param2", out.Resource.Job["my_job"].Parameter[1].Name)
assert.Nil(t, out.Data)
}

Expand Down

0 comments on commit c0ebfb8

Please sign in to comment.