Skip to content

Commit 373daf2

Browse files
committed
chore(ps): restart types
1 parent 656dcb6 commit 373daf2

2 files changed

Lines changed: 25 additions & 31 deletions

File tree

ps/ps.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,13 @@ func Scale(c *drycc.Client, appID string, targets map[string]int) error {
105105
// Restart restarts an app's processes. To restart all app processes, pass empty strings for
106106
// procType and name. To restart an specific process, pass an procType by leave name empty.
107107
// To restart a specific instance, pass a procType and a name.
108-
func Restart(c *drycc.Client, appID string, procType string) error {
109-
u := fmt.Sprintf("/v2/apps/%s/pods/", appID)
110-
111-
if procType == "" {
112-
u += "restart/"
113-
} else {
114-
u += procType + "/restart/"
108+
func Restart(c *drycc.Client, appID string, targets map[string]string) error {
109+
u := fmt.Sprintf("/v2/apps/%s/pods/restart/", appID)
110+
body, err := json.Marshal(targets)
111+
if err != nil {
112+
return err
115113
}
116-
117-
res, err := c.Request("POST", u, nil)
114+
res, err := c.Request("POST", u, body)
118115
if err != nil && !drycc.IsErrAPIMismatch(err) {
119116
return err
120117
}

ps/ps_test.go

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ const podStateFixture string = `
6767

6868
const scaleExpected string = `{"web":2}`
6969

70+
const restartExpected string = `{"types":"web,worker"}`
71+
7072
type fakeHTTPServer struct{}
7173

7274
func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
@@ -83,11 +85,19 @@ func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
8385
}
8486

8587
if req.URL.Path == "/v2/apps/example-go/pods/restart/" && req.Method == "POST" {
86-
res.WriteHeader(http.StatusNoContent)
87-
return
88-
}
88+
body, err := io.ReadAll(req.Body)
8989

90-
if req.URL.Path == "/v2/apps/example-go/pods/web/restart/" && req.Method == "POST" {
90+
if err != nil {
91+
fmt.Println(err)
92+
res.WriteHeader(http.StatusInternalServerError)
93+
res.Write(nil)
94+
}
95+
if string(body) != restartExpected {
96+
fmt.Printf("Expected '%s', Got '%s'\n", restartExpected, body)
97+
res.WriteHeader(http.StatusInternalServerError)
98+
res.Write(nil)
99+
return
100+
}
91101
res.WriteHeader(http.StatusNoContent)
92102
return
93103
}
@@ -235,24 +245,13 @@ func TestPodLogs(t *testing.T) {
235245
}
236246
}
237247

238-
type testExpected struct {
239-
Name string
240-
Type string
241-
Expected api.PodsList
242-
}
243-
244248
func TestAppsRestart(t *testing.T) {
245249
t.Parallel()
246250

247251
started := time.Time{}
248252
started.UnmarshalText([]byte("2016-02-13T00:47:52"))
249-
tests := []testExpected{
250-
{
251-
Type: "",
252-
},
253-
{
254-
Type: "web",
255-
},
253+
types := map[string]string{
254+
"types": "web,worker",
256255
}
257256

258257
handler := fakeHTTPServer{}
@@ -264,12 +263,10 @@ func TestAppsRestart(t *testing.T) {
264263
t.Fatal(err)
265264
}
266265

267-
for _, test := range tests {
268-
err := Restart(drycc, "example-go", test.Type)
266+
err = Restart(drycc, "example-go", types)
269267

270-
if err != nil {
271-
t.Error(err)
272-
}
268+
if err != nil {
269+
t.Error(err)
273270
}
274271
}
275272

0 commit comments

Comments
 (0)