@@ -32,6 +32,39 @@ const processesFixture string = `
3232 ]
3333}`
3434
35+ const podStateFixture string = `
36+ {
37+ "count": 1,
38+ "next": null,
39+ "previous": null,
40+ "results": [{
41+ "container": "web",
42+ "image": "registry.drycc.cc/base/base",
43+ "command": ["bash", "-c"],
44+ "args": ["sleep 3600s"],
45+ "state": {
46+ "running": {
47+ "startedAt": "2024-05-21T02:27:03+00:00"
48+ },
49+ "waiting": {
50+ "message": "container create failed: executable file './start.sh' not found in $PATH: No such file or directory\n",
51+ "reason": "CreateContainerError"
52+ }
53+ },
54+ "lastState": {
55+ "terminated": {
56+ "containerID": "cri-o://ccfc73b0b4d966af4f93ca871a04fa97460620cd8005c1c36f7734a08ba49ed0",
57+ "exitCode": 1,
58+ "finishedAt": "2024-05-21T02:27:03+00:00",
59+ "reason": "Error",
60+ "startedAt": "2024-05-21T02:26:33+00:00"
61+ }
62+ },
63+ "ready": true,
64+ "restartCount": 1
65+ }]
66+ }`
67+
3568const scaleExpected string = `{"web":2}`
3669
3770type fakeHTTPServer struct {}
@@ -44,6 +77,11 @@ func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
4477 return
4578 }
4679
80+ if req .URL .Path == "/v2/apps/example-go/pods/test-pod-web/describe/" && req .Method == "GET" {
81+ res .Write ([]byte (podStateFixture ))
82+ return
83+ }
84+
4785 if req .URL .Path == "/v2/apps/example-go/pods/restart/" && req .Method == "POST" {
4886 res .WriteHeader (http .StatusNoContent )
4987 return
@@ -235,6 +273,54 @@ func TestAppsRestart(t *testing.T) {
235273 }
236274}
237275
276+ func TestDescribe (t * testing.T ) {
277+ t .Parallel ()
278+
279+ handler := fakeHTTPServer {}
280+ server := httptest .NewServer (& handler )
281+ defer server .Close ()
282+
283+ drycc , err := drycc .New (false , server .URL , "abc" )
284+ if err != nil {
285+ t .Fatal (err )
286+ }
287+ actual , _ , err := Describe (drycc , "example-go" , "test-pod-web" , 100 )
288+ if err != nil {
289+ t .Error (err )
290+ }
291+ expected := api.PodState {
292+ {
293+ Container : "web" ,
294+ Image : "registry.drycc.cc/base/base" ,
295+ Command : []string {"bash" , "-c" },
296+ Args : []string {"sleep 3600s" },
297+ State : map [string ]map [string ]interface {}{
298+ "running" : {
299+ "startedAt" : "2024-05-21T02:27:03+00:00" ,
300+ },
301+ "waiting" : {
302+ "message" : "container create failed: executable file './start.sh' not found in $PATH: No such file or directory\n " ,
303+ "reason" : "CreateContainerError" ,
304+ },
305+ },
306+ LastState : map [string ]map [string ]interface {}{
307+ "terminated" : {
308+ "containerID" : "cri-o://ccfc73b0b4d966af4f93ca871a04fa97460620cd8005c1c36f7734a08ba49ed0" ,
309+ "exitCode" : 1 ,
310+ "finishedAt" : "2024-05-21T02:27:03+00:00" ,
311+ "reason" : "Error" ,
312+ "startedAt" : "2024-05-21T02:26:33+00:00" ,
313+ },
314+ },
315+ Ready : true ,
316+ RestartCount : 1 ,
317+ },
318+ }
319+ if ! reflect .DeepEqual (actual [0 ].State , expected [0 ].State ) {
320+ t .Error (fmt .Errorf ("Expected %v, Got %v" , actual [0 ].State , expected [0 ].State ))
321+ }
322+ }
323+
238324func TestScale (t * testing.T ) {
239325 t .Parallel ()
240326
0 commit comments