|
| 1 | +package jobs |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/databricks/terraform-provider-databricks/qa" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func commonFixtures() []qa.HTTPFixture { |
| 9 | + return []qa.HTTPFixture{ |
| 10 | + { |
| 11 | + Method: "GET", |
| 12 | + Resource: "/api/2.0/jobs/list", |
| 13 | + Response: JobList{ |
| 14 | + Jobs: []Job{ |
| 15 | + { |
| 16 | + JobID: 123, |
| 17 | + Settings: &JobSettings{ |
| 18 | + Name: "First", |
| 19 | + }, |
| 20 | + }, |
| 21 | + { |
| 22 | + JobID: 234, |
| 23 | + Settings: &JobSettings{ |
| 24 | + Name: "Second", |
| 25 | + }, |
| 26 | + }, |
| 27 | + }, |
| 28 | + }, |
| 29 | + }, |
| 30 | + } |
| 31 | + |
| 32 | +} |
| 33 | +func TestDataSourceQueryableJobMatchesId(t *testing.T) { |
| 34 | + qa.ResourceFixture{ |
| 35 | + Fixtures: commonFixtures(), |
| 36 | + Resource: DataSourceJob(), |
| 37 | + Read: true, |
| 38 | + New: true, |
| 39 | + NonWritable: true, |
| 40 | + HCL: `job_id = "234"`, |
| 41 | + ID: "_", |
| 42 | + }.ApplyAndExpectData(t, map[string]any{ |
| 43 | + "job_id": "234", |
| 44 | + "job_settings.0.settings.0.name": "Second", |
| 45 | + }) |
| 46 | +} |
| 47 | + |
| 48 | +func TestDataSourceQueryableJobMatchesName(t *testing.T) { |
| 49 | + qa.ResourceFixture{ |
| 50 | + Fixtures: commonFixtures(), |
| 51 | + Resource: DataSourceJob(), |
| 52 | + Read: true, |
| 53 | + NonWritable: true, |
| 54 | + HCL: `job_name = "First"`, |
| 55 | + ID: "_", |
| 56 | + }.ApplyAndExpectData(t, map[string]any{ |
| 57 | + "job_id": "123", |
| 58 | + "job_settings.0.settings.0.name": "First", |
| 59 | + }) |
| 60 | +} |
| 61 | + |
| 62 | +func TestDataSourceQueryableJobNoMatchName(t *testing.T) { |
| 63 | + qa.ResourceFixture{ |
| 64 | + Fixtures: commonFixtures(), |
| 65 | + Resource: DataSourceJob(), |
| 66 | + Read: true, |
| 67 | + NonWritable: true, |
| 68 | + HCL: `job_name= "Third"`, |
| 69 | + ID: "_", |
| 70 | + }.ExpectError(t, "no job found with specified name or id") |
| 71 | +} |
| 72 | + |
| 73 | +func TestDataSourceQueryableJobNoMatchId(t *testing.T) { |
| 74 | + qa.ResourceFixture{ |
| 75 | + Fixtures: commonFixtures(), |
| 76 | + Resource: DataSourceJob(), |
| 77 | + Read: true, |
| 78 | + NonWritable: true, |
| 79 | + HCL: `job_id= "567"`, |
| 80 | + ID: "_", |
| 81 | + }.ExpectError(t, "no job found with specified name or id") |
| 82 | +} |
0 commit comments