-
Notifications
You must be signed in to change notification settings - Fork 423
/
Copy pathgs_test.go
124 lines (118 loc) · 3.66 KB
/
gs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package storage
import (
"context"
"testing"
"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/terraform-provider-databricks/clusters"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/databricks/terraform-provider-databricks/qa"
"github.com/stretchr/testify/assert"
)
func TestCreateOrValidateClusterForGoogleStorage_Failures(t *testing.T) {
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
{
MatchAny: true,
ReuseRequest: true,
Status: 404,
Response: &apierr.APIError{
ErrorCode: "NOT_FOUND",
StatusCode: 404,
Message: "nope",
},
},
}, func(ctx context.Context, client *common.DatabricksClient) {
d := ResourceMount().ToResource().TestResourceData()
err := createOrValidateClusterForGoogleStorage(ctx, client, d, "a", "")
assert.EqualError(t, err, "cannot re-create mounting cluster: nope")
err = createOrValidateClusterForGoogleStorage(ctx, client, d, "", "b")
assert.EqualError(t, err, "cannot create mounting cluster: nope")
})
}
func TestCreateOrValidateClusterForGoogleStorage_WorksOnDeletedCluster(t *testing.T) {
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/clusters/get?cluster_id=removed-cluster",
Status: 404,
Response: &apierr.APIError{
ErrorCode: "NOT_FOUND",
StatusCode: 404,
Message: "cluster deleted",
},
},
{
Method: "GET",
Resource: "/api/2.0/clusters/list",
Response: clusters.ClusterList{
Clusters: []clusters.ClusterInfo{},
},
},
{
ReuseRequest: true,
Method: "GET",
Resource: "/api/2.1/clusters/spark-versions",
},
{
ReuseRequest: true,
Method: "GET",
Resource: "/api/2.1/clusters/list-node-types",
},
{
Method: "POST",
Resource: "/api/2.0/clusters/create",
ExpectedRequest: clusters.Cluster{
CustomTags: map[string]string{
"ResourceClass": "SingleNode",
},
ClusterName: "terraform-mount-gcs-03a56ec1d1576b505aabf088337cbf36",
GcpAttributes: &clusters.GcpAttributes{
GoogleServiceAccount: "service-account",
},
SparkVersion: "11.3.x-scala2.12",
NumWorkers: 0,
NodeTypeID: "i3.xlarge",
AutoterminationMinutes: 10,
SparkConf: map[string]string{
"spark.databricks.cluster.profile": "singleNode",
"spark.master": "local[*]",
"spark.scheduler.mode": "FIFO",
},
},
Response: clusters.ClusterID{
ClusterID: "new-cluster",
},
},
{
Method: "GET",
Resource: "/api/2.0/clusters/get?cluster_id=new-cluster",
Response: clusters.ClusterInfo{
ClusterID: "new-cluster",
State: "RUNNING",
StateMessage: "created",
},
},
}, func(ctx context.Context, client *common.DatabricksClient) {
d := ResourceMount().ToResource().TestResourceData()
err := createOrValidateClusterForGoogleStorage(ctx, client, d, "removed-cluster", "service-account")
assert.NoError(t, err)
assert.Equal(t, "new-cluster", d.Get("cluster_id"))
})
}
func TestCreateOrValidateClusterForGoogleStorage_FailsOnErrorGettingCluster(t *testing.T) {
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/clusters/get?cluster_id=my-cluster",
Status: 500,
Response: apierr.APIError{
ErrorCode: "SERVER_ERROR",
StatusCode: 500,
Message: "Server error",
},
},
}, func(ctx context.Context, client *common.DatabricksClient) {
d := ResourceMount().ToResource().TestResourceData()
err := createOrValidateClusterForGoogleStorage(ctx, client, d, "my-cluster", "service-account")
assert.EqualError(t, err, "cannot get mounting cluster: Server error")
})
}