@@ -67,6 +67,8 @@ const podStateFixture string = `
6767
6868const scaleExpected string = `{"web":2}`
6969
70+ const restartExpected string = `{"types":"web,worker"}`
71+
7072type fakeHTTPServer struct {}
7173
7274func (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-
244248func 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