This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
fixtures.go
167 lines (153 loc) · 5.32 KB
/
fixtures.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package testing
import (
"fmt"
"net/http"
"testing"
"github.com/huaweicloud/golangsdk/openstack/mrs/v2/jobs"
th "github.com/huaweicloud/golangsdk/testhelper"
"github.com/huaweicloud/golangsdk/testhelper/client"
)
const (
expectedCreateResponse = `
{
"job_submit_result": {
"job_id": "3c0cf394-5da2-46a7-92df-795d998edea7",
"state": "COMPLETE"
}
}`
expectedGetResponse = `
{
"job_detail": {
"app_id": "application_1627718181153_0003",
"arguments": "[--class, com.huawei.bigdata.spark.examples.DriverBehavior, --master, yarn-cluster, obs://obs-demo-analysis-tf/program/driver_behavior.jar, ACCESS_KEY, SECRET_KEY, 1, obs://obs-demo-analysis-tf/input, obs://obs-demo-analysis-tf/output]",
"job_id": "3c0cf394-5da2-46a7-92df-795d998edea7",
"job_name": "terraform_test",
"job_progress": 100,
"job_result": "FAILED",
"job_state": "FINISHED",
"job_type": "SparkSubmit",
"launcher_id": "application_1627718181153_0002",
"started_time": 1627719118083,
"submitted_time": 1627719066265,
"user": "terraform"
}
}`
expectedListResponse = `
{
"total_record":1,
"job_list":[
{
"app_id": "application_1627718181153_0003",
"arguments": "[--class, com.huawei.bigdata.spark.examples.DriverBehavior, --master, yarn-cluster, obs://obs-demo-analysis-tf/program/driver_behavior.jar, ACCESS_KEY, SECRET_KEY, 1, obs://obs-demo-analysis-tf/input, obs://obs-demo-analysis-tf/output]",
"job_id": "3c0cf394-5da2-46a7-92df-795d998edea7",
"job_name": "terraform_test",
"job_progress": 100,
"job_result": "FAILED",
"job_state": "FINISHED",
"job_type": "SparkSubmit",
"launcher_id": "application_1627718181153_0002",
"started_time": 1627719118083,
"submitted_time": 1627719066265,
"user": "terraform"
}
]
}`
)
var (
createOpts = &jobs.CreateOpts{
JobName: "terraform_test",
JobType: "SparkSubmit",
Arguments: []string{
"--class",
"com.huawei.bigdata.spark.examples.DriverBehavior",
"--master",
"yarn-cluster",
"obs://obs-demo-analysis-tf/program/driver_behavior.jar",
"ACCESS_KEY",
"SECRET_KEY",
"1",
"obs://obs-demo-analysis-tf/input",
"obs://obs-demo-analysis-tf/output",
},
}
expectedCreateResponseData = &jobs.CreateResp{
JobSubmitResult: jobs.JobResp{
JobId: "3c0cf394-5da2-46a7-92df-795d998edea7",
State: "COMPLETE",
},
}
expectedGetResponseData = &jobs.Job{
AppId: "application_1627718181153_0003",
Arguments: "[--class, com.huawei.bigdata.spark.examples.DriverBehavior, --master, yarn-cluster, obs://obs-demo-analysis-tf/program/driver_behavior.jar, ACCESS_KEY, SECRET_KEY, 1, obs://obs-demo-analysis-tf/input, obs://obs-demo-analysis-tf/output]",
JobId: "3c0cf394-5da2-46a7-92df-795d998edea7",
JobName: "terraform_test",
JobProgress: 100,
JobResult: "FAILED",
JobState: "FINISHED",
JobType: "SparkSubmit",
LauncherId: "application_1627718181153_0002",
StartedTime: 1627719118083,
SubmittedTime: 1627719066265,
User: "terraform",
}
expectedListResponseData = []jobs.Job{
{
AppId: "application_1627718181153_0003",
Arguments: "[--class, com.huawei.bigdata.spark.examples.DriverBehavior, --master, yarn-cluster, obs://obs-demo-analysis-tf/program/driver_behavior.jar, ACCESS_KEY, SECRET_KEY, 1, obs://obs-demo-analysis-tf/input, obs://obs-demo-analysis-tf/output]",
JobId: "3c0cf394-5da2-46a7-92df-795d998edea7",
JobName: "terraform_test",
JobProgress: 100,
JobResult: "FAILED",
JobState: "FINISHED",
JobType: "SparkSubmit",
LauncherId: "application_1627718181153_0002",
StartedTime: 1627719118083,
SubmittedTime: 1627719066265,
User: "terraform",
},
}
deleteOpts = jobs.DeleteOpts{
JobIds: []string{
"3c0cf394-5da2-46a7-92df-795d998edea7",
},
}
)
func handleV2JobCreate(t *testing.T) {
th.Mux.HandleFunc("/clusters/986416ea-e26b-40f1-b371-cd7be87376a2/job-executions",
func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, _ = fmt.Fprint(w, expectedCreateResponse)
})
}
func handleV2JobGet(t *testing.T) {
th.Mux.HandleFunc("/clusters/986416ea-e26b-40f1-b371-cd7be87376a2/job-executions"+
"/3c0cf394-5da2-46a7-92df-795d998edea7", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, _ = fmt.Fprint(w, expectedGetResponse)
})
}
func handleV2JobList(t *testing.T) {
th.Mux.HandleFunc("/clusters/986416ea-e26b-40f1-b371-cd7be87376a2/job-executions",
func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, _ = fmt.Fprint(w, expectedListResponse)
})
}
func handleV2JobDelete(t *testing.T) {
th.Mux.HandleFunc("/clusters/986416ea-e26b-40f1-b371-cd7be87376a2/job-executions/batch-delete",
func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusAccepted)
})
}