Fix conversion of job parameters (#744)

## 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.
This commit is contained in:
Pieter Noordhuis 2023-09-07 14:48:59 +02:00 committed by GitHub
parent 50b2c0b83b
commit c0ebfb8101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -90,6 +90,12 @@ func BundleToTerraform(config *config.Root) (*schema.Root, bool) {
Tag: git.GitTag, 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 tfroot.Resource.Job[k] = &dst

View File

@ -29,6 +29,16 @@ func TestConvertJob(t *testing.T) {
GitProvider: jobs.GitProviderGitHub, GitProvider: jobs.GitProviderGitHub,
GitUrl: "https://github.com/foo/bar", GitUrl: "https://github.com/foo/bar",
}, },
Parameters: []jobs.JobParameterDefinition{
{
Name: "param1",
Default: "default1",
},
{
Name: "param2",
Default: "default2",
},
},
}, },
} }
@ -44,6 +54,9 @@ func TestConvertJob(t *testing.T) {
assert.Equal(t, "my job", out.Resource.Job["my_job"].Name) assert.Equal(t, "my job", out.Resource.Job["my_job"].Name)
assert.Len(t, out.Resource.Job["my_job"].JobCluster, 1) 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.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) assert.Nil(t, out.Data)
} }