Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kanterov committed Jan 29, 2024
1 parent 54a87b7 commit 01fbcb8
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions jobs/resource_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,88 @@ func TestResourceJobCreate_JobParameters(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "231", d.Id())
}

func TestResourceJobCreate_JobParameters_EmptyDefault(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "POST",
Resource: "/api/2.1/jobs/create",
ExpectedRequest: JobSettings{
Name: "JobParameterTesting",
MaxConcurrentRuns: 1,
Tasks: []JobTaskSettings{
{
TaskKey: "a",
},
},
Parameters: []jobs.JobParameterDefinition{
{
Name: "key",
Default: "",
},
},
},
Response: Job{
JobID: 231,
},
},
{
Method: "GET",
Resource: "/api/2.1/jobs/get?job_id=231",
Response: Job{
// good enough for mock
Settings: &JobSettings{
Tasks: []JobTaskSettings{
{
TaskKey: "a",
},
},
Parameters: []jobs.JobParameterDefinition{
{
Name: "key",
Default: "",
},
},
},
},
},
},
Create: true,
Resource: ResourceJob(),
HCL: `
name = "JobParameterTesting"
parameter {
name = "key"
default = ""
}
task {
task_key = "a"
}`,
}.Apply(t)
assert.NoError(t, err)
assert.Equal(t, "231", d.Id())
}

func TestResourceJobCreate_JobParameters_DefaultIsRequired(t *testing.T) {
qa.ResourceFixture{
Create: true,
Resource: ResourceJob(),
HCL: `
name = "JobParameterTesting"
parameter {
name = "key"
}
task {
task_key = "a"
}`,
}.ExpectError(t, "invalid config supplied. [parameter.#.default] Missing required argument")
}

func TestResourceJobCreate_JobClusters(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
Expand Down

0 comments on commit 01fbcb8

Please sign in to comment.