Skip to content

Commit 4fdd843

Browse files
committed
chore(controller-sdk-go): change restart api
1 parent a334918 commit 4fdd843

2 files changed

Lines changed: 8 additions & 116 deletions

File tree

ps/ps.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,40 +71,25 @@ func Scale(c *drycc.Client, appID string, targets map[string]int) error {
7171
}
7272

7373
res, err := c.Request("POST", u, body)
74-
if err == nil {
75-
return res.Body.Close()
76-
}
74+
defer res.Body.Close()
7775
return err
7876
}
7977

8078
// Restart restarts an app's processes. To restart all app processes, pass empty strings for
8179
// procType and name. To restart an specific process, pass an procType by leave name empty.
8280
// To restart a specific instance, pass a procType and a name.
83-
func Restart(c *drycc.Client, appID string, procType string, name string) (api.PodsList, error) {
81+
func Restart(c *drycc.Client, appID string, procType string) error {
8482
u := fmt.Sprintf("/v2/apps/%s/pods/", appID)
8583

8684
if procType == "" {
8785
u += "restart/"
8886
} else {
89-
if name == "" {
90-
u += procType + "/restart/"
91-
} else {
92-
u += procType + "/" + name + "/restart/"
93-
}
87+
u += procType + "/restart/"
9488
}
9589

96-
res, reqErr := c.Request("POST", u, nil)
97-
if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
98-
return []api.Pods{}, reqErr
99-
}
90+
res, err := c.Request("POST", u, nil)
10091
defer res.Body.Close()
101-
102-
procs := []api.Pods{}
103-
if err := json.NewDecoder(res.Body).Decode(&procs); err != nil {
104-
return []api.Pods{}, err
105-
}
106-
107-
return procs, reqErr
92+
return err
10893
}
10994

11095
// ByType organizes processes of an app by process type.

ps/ps_test.go

Lines changed: 3 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,6 @@ const processesFixture string = `
3131
]
3232
}`
3333

34-
const restartAllFixture string = `[
35-
{
36-
"release": "v2",
37-
"type": "web",
38-
"name": "example-go-v2-web-45678",
39-
"state": "up",
40-
"started": "2016-02-13T00:47:52"
41-
}
42-
]
43-
`
44-
45-
const restartWorkerFixture string = `[
46-
{
47-
"release": "v2",
48-
"type": "worker",
49-
"name": "example-go-v2-worker-45678",
50-
"state": "up",
51-
"started": "2016-02-13T00:47:52"
52-
}
53-
]
54-
`
55-
56-
const restartWebTwoFixture string = `[
57-
{
58-
"release": "v2",
59-
"type": "web",
60-
"name": "example-go-v2-web-45678",
61-
"state": "up",
62-
"started": "2016-02-13T00:47:52"
63-
}
64-
]
65-
`
66-
6734
const scaleExpected string = `{"web":2}`
6835

6936
var upgrader = websocket.Upgrader{} // use default options
@@ -102,22 +69,12 @@ func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
10269
}
10370

10471
if req.URL.Path == "/v2/apps/example-go/pods/restart/" && req.Method == "POST" {
105-
res.Write([]byte(restartAllFixture))
72+
res.WriteHeader(http.StatusNoContent)
10673
return
10774
}
10875

10976
if req.URL.Path == "/v2/apps/example-go/pods/web/restart/" && req.Method == "POST" {
110-
res.Write([]byte(restartWebTwoFixture))
111-
return
112-
}
113-
114-
if req.URL.Path == "/v2/apps/example-go/pods/worker/example-go-v2-worker-45678/restart/" && req.Method == "POST" {
115-
res.Write([]byte(restartWorkerFixture))
116-
return
117-
}
118-
119-
if req.URL.Path == "/v2/apps/example-go/pods/worker/worker-45678/restart/" && req.Method == "POST" {
120-
res.Write([]byte(restartWorkerFixture))
77+
res.WriteHeader(http.StatusNoContent)
12178
return
12279
}
12380

@@ -219,56 +176,10 @@ func TestAppsRestart(t *testing.T) {
219176
started.UnmarshalText([]byte("2016-02-13T00:47:52"))
220177
tests := []testExpected{
221178
{
222-
Name: "",
223179
Type: "",
224-
Expected: []api.Pods{
225-
{
226-
Release: "v2",
227-
Type: "web",
228-
Name: "example-go-v2-web-45678",
229-
State: "up",
230-
Started: started,
231-
},
232-
},
233180
},
234181
{
235-
Name: "example-go-v2-worker-45678",
236-
Type: "worker",
237-
Expected: []api.Pods{
238-
{
239-
Release: "v2",
240-
Type: "worker",
241-
Name: "example-go-v2-worker-45678",
242-
State: "up",
243-
Started: started,
244-
},
245-
},
246-
},
247-
{
248-
Name: "worker-45678",
249-
Type: "worker",
250-
Expected: []api.Pods{
251-
{
252-
Release: "v2",
253-
Type: "worker",
254-
Name: "example-go-v2-worker-45678",
255-
State: "up",
256-
Started: started,
257-
},
258-
},
259-
},
260-
{
261-
Name: "",
262182
Type: "web",
263-
Expected: []api.Pods{
264-
{
265-
Release: "v2",
266-
Type: "web",
267-
Name: "example-go-v2-web-45678",
268-
State: "up",
269-
Started: started,
270-
},
271-
},
272183
},
273184
}
274185

@@ -282,15 +193,11 @@ func TestAppsRestart(t *testing.T) {
282193
}
283194

284195
for _, test := range tests {
285-
actual, err := Restart(drycc, "example-go", test.Type, test.Name)
196+
err := Restart(drycc, "example-go", test.Type)
286197

287198
if err != nil {
288199
t.Error(err)
289200
}
290-
291-
if !reflect.DeepEqual(test.Expected, actual) {
292-
t.Error(fmt.Errorf("Expected %v, Got %v", test.Expected, actual))
293-
}
294201
}
295202
}
296203

0 commit comments

Comments
 (0)