|
7 | 7 | "time" |
8 | 8 |
|
9 | 9 | "github.com/databrickslabs/terraform-provider-databricks/common" |
10 | | - |
11 | 10 | "github.com/databrickslabs/terraform-provider-databricks/qa" |
12 | 11 | "github.com/stretchr/testify/assert" |
13 | 12 | "github.com/stretchr/testify/require" |
@@ -457,42 +456,6 @@ func TestResourceJobCreateSingleNode_Fail(t *testing.T) { |
457 | 456 | require.Equal(t, true, strings.Contains(err.Error(), "NumWorkers could be 0 only for SingleNode clusters")) |
458 | 457 | } |
459 | 458 |
|
460 | | -func TestResourceJobCreate_Error(t *testing.T) { |
461 | | - d, err := qa.ResourceFixture{ |
462 | | - Fixtures: []qa.HTTPFixture{ |
463 | | - { |
464 | | - Method: "POST", |
465 | | - Resource: "/api/2.0/jobs/create", |
466 | | - Response: common.APIErrorBody{ |
467 | | - ErrorCode: "INVALID_REQUEST", |
468 | | - Message: "Internal error happened", |
469 | | - }, |
470 | | - Status: 400, |
471 | | - }, |
472 | | - }, |
473 | | - Resource: ResourceJob(), |
474 | | - HCL: `existing_cluster_id = "abc" |
475 | | - max_concurrent_runs = 1 |
476 | | - max_retries = 3 |
477 | | - min_retry_interval_millis = 5000 |
478 | | - name = "Featurizer" |
479 | | - retry_on_timeout = true |
480 | | -
|
481 | | - spark_jar_task { |
482 | | - main_class_name = "com.labs.BarMain" |
483 | | - } |
484 | | - library { |
485 | | - jar = "dbfs://aa/bb/cc.jar" |
486 | | - } |
487 | | - library { |
488 | | - jar = "dbfs://ff/gg/hh.jar" |
489 | | - }`, |
490 | | - Create: true, |
491 | | - }.Apply(t) |
492 | | - qa.AssertErrorStartsWith(t, err, "Internal error happened") |
493 | | - assert.Equal(t, "", d.Id(), "Id should be empty for error creates") |
494 | | -} |
495 | | - |
496 | 459 | func TestResourceJobRead(t *testing.T) { |
497 | 460 | d, err := qa.ResourceFixture{ |
498 | 461 | Fixtures: []qa.HTTPFixture{ |
@@ -676,6 +639,62 @@ func TestResourceJobUpdate(t *testing.T) { |
676 | 639 | assert.Equal(t, "Featurizer New", d.Get("name")) |
677 | 640 | } |
678 | 641 |
|
| 642 | +func TestResourceJobUpdate_Tasks(t *testing.T) { |
| 643 | + qa.ResourceFixture{ |
| 644 | + Fixtures: []qa.HTTPFixture{ |
| 645 | + { |
| 646 | + Method: "POST", |
| 647 | + Resource: "/api/2.1/jobs/reset", |
| 648 | + ExpectedRequest: UpdateJobRequest{ |
| 649 | + JobID: 789, |
| 650 | + NewSettings: &JobSettings{ |
| 651 | + Name: "Featurizer New", |
| 652 | + Tasks: []JobTaskSettings{ |
| 653 | + { |
| 654 | + ExistingClusterID: "abc", |
| 655 | + SparkJarTask: &SparkJarTask{ |
| 656 | + MainClassName: "com.labs.BarMain", |
| 657 | + }, |
| 658 | + }, |
| 659 | + }, |
| 660 | + MaxConcurrentRuns: 1, |
| 661 | + }, |
| 662 | + }, |
| 663 | + Response: Job{ |
| 664 | + JobID: 789, |
| 665 | + }, |
| 666 | + }, |
| 667 | + { |
| 668 | + Method: "GET", |
| 669 | + Resource: "/api/2.1/jobs/get?job_id=789", |
| 670 | + Response: Job{ |
| 671 | + Settings: &JobSettings{ |
| 672 | + Tasks: []JobTaskSettings{ |
| 673 | + { |
| 674 | + ExistingClusterID: "abc", |
| 675 | + SparkJarTask: &SparkJarTask{ |
| 676 | + MainClassName: "com.labs.BarMain", |
| 677 | + }, |
| 678 | + }, |
| 679 | + }, |
| 680 | + }, |
| 681 | + }, |
| 682 | + }, |
| 683 | + }, |
| 684 | + ID: "789", |
| 685 | + Update: true, |
| 686 | + Resource: ResourceJob(), |
| 687 | + HCL: ` |
| 688 | + name = "Featurizer New" |
| 689 | + task { |
| 690 | + existing_cluster_id = "abc" |
| 691 | + spark_jar_task { |
| 692 | + main_class_name = "com.labs.BarMain" |
| 693 | + } |
| 694 | + }`, |
| 695 | + }.ApplyNoError(t) |
| 696 | +} |
| 697 | + |
679 | 698 | func TestResourceJobUpdate_Restart(t *testing.T) { |
680 | 699 | d, err := qa.ResourceFixture{ |
681 | 700 | Fixtures: []qa.HTTPFixture{ |
@@ -905,44 +924,6 @@ func TestJobRestarts(t *testing.T) { |
905 | 924 | }) |
906 | 925 | } |
907 | 926 |
|
908 | | -func TestResourceJobUpdate_Error(t *testing.T) { |
909 | | - d, err := qa.ResourceFixture{ |
910 | | - Fixtures: []qa.HTTPFixture{ |
911 | | - { |
912 | | - Method: "POST", |
913 | | - Resource: "/api/2.0/jobs/reset", |
914 | | - Response: common.APIErrorBody{ |
915 | | - ErrorCode: "INVALID_REQUEST", |
916 | | - Message: "Internal error happened", |
917 | | - }, |
918 | | - Status: 400, |
919 | | - }, |
920 | | - }, |
921 | | - ID: "789", |
922 | | - Update: true, |
923 | | - Resource: ResourceJob(), |
924 | | - HCL: `existing_cluster_id = "abc" |
925 | | - max_concurrent_runs = 1 |
926 | | - max_retries = 3 |
927 | | - min_retry_interval_millis = 5000 |
928 | | - name = "Featurizer New" |
929 | | - retry_on_timeout = true |
930 | | -
|
931 | | - spark_jar_task { |
932 | | - main_class_name = "com.labs.BarMain" |
933 | | - parameters = ["--cleanup", "full"] |
934 | | - } |
935 | | - library { |
936 | | - jar = "dbfs://aa/bb/cc.jar" |
937 | | - } |
938 | | - library { |
939 | | - jar = "dbfs://ff/gg/hh.jar" |
940 | | - }`, |
941 | | - }.Apply(t) |
942 | | - qa.AssertErrorStartsWith(t, err, "Internal error happened") |
943 | | - assert.Equal(t, "789", d.Id()) |
944 | | -} |
945 | | - |
946 | 927 | func TestResourceJobDelete(t *testing.T) { |
947 | 928 | d, err := qa.ResourceFixture{ |
948 | 929 | Fixtures: []qa.HTTPFixture{ |
@@ -987,27 +968,6 @@ func TestResourceJobUpdate_FailNumWorkersZero(t *testing.T) { |
987 | 968 | require.Equal(t, true, strings.Contains(err.Error(), "NumWorkers could be 0 only for SingleNode clusters")) |
988 | 969 | } |
989 | 970 |
|
990 | | -func TestResourceJobDelete_Error(t *testing.T) { |
991 | | - d, err := qa.ResourceFixture{ |
992 | | - Fixtures: []qa.HTTPFixture{ |
993 | | - { |
994 | | - Method: "POST", |
995 | | - Resource: "/api/2.0/jobs/delete", |
996 | | - Response: common.APIErrorBody{ |
997 | | - ErrorCode: "INVALID_REQUEST", |
998 | | - Message: "Internal error happened", |
999 | | - }, |
1000 | | - Status: 400, |
1001 | | - }, |
1002 | | - }, |
1003 | | - ID: "789", |
1004 | | - Delete: true, |
1005 | | - Resource: ResourceJob(), |
1006 | | - }.Apply(t) |
1007 | | - qa.AssertErrorStartsWith(t, err, "Internal error happened") |
1008 | | - assert.Equal(t, "789", d.Id()) |
1009 | | -} |
1010 | | - |
1011 | 971 | func TestJobsAPIList(t *testing.T) { |
1012 | 972 | qa.HTTPFixturesApply(t, []qa.HTTPFixture{ |
1013 | 973 | { |
@@ -1057,3 +1017,21 @@ func TestJobsAPIRunsList(t *testing.T) { |
1057 | 1017 | assert.Len(t, l.Runs, 1) |
1058 | 1018 | }) |
1059 | 1019 | } |
| 1020 | + |
| 1021 | +func TestJobResourceCornerCases_HTTP(t *testing.T) { |
| 1022 | + qa.ResourceCornerCases(t, ResourceJob(), qa.CornerCaseID("10")) |
| 1023 | +} |
| 1024 | + |
| 1025 | +func TestJobResourceCornerCases_WrongID(t *testing.T) { |
| 1026 | + qa.ResourceCornerCases(t, ResourceJob(), |
| 1027 | + qa.CornerCaseID("x"), |
| 1028 | + qa.CornerCaseSkipCRUD("create"), |
| 1029 | + qa.CornerCaseExpectError(`strconv.ParseInt: parsing "x": invalid syntax`)) |
| 1030 | +} |
| 1031 | + |
| 1032 | +func TestJobResource_SparkConfDiffSuppress(t *testing.T) { |
| 1033 | + jr := ResourceJob() |
| 1034 | + scs := common.MustSchemaPath(jr.Schema, "new_cluster", "spark_conf") |
| 1035 | + assert.True(t, scs.DiffSuppressFunc("new_cluster.0.spark_conf.%", "1", "0", nil)) |
| 1036 | + assert.False(t, scs.DiffSuppressFunc("new_cluster.0.spark_conf.%", "1", "1", nil)) |
| 1037 | +} |
0 commit comments