Skip to content

Commit 079305c

Browse files
committed
fix(apps): AppsScale returns a []ContainerType
1 parent c0f0279 commit 079305c

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

apps.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package scalingo
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
6-
"net/http"
77
"time"
88

99
httpclient "github.com/Scalingo/go-scalingo/v10/http"
@@ -32,7 +32,7 @@ type AppsService interface {
3232
AppsStats(ctx context.Context, app string) (*AppStatsRes, error)
3333
AppsContainerTypes(ctx context.Context, app string) ([]ContainerType, error)
3434
AppsContainersPs(ctx context.Context, app string) ([]Container, error)
35-
AppsScale(ctx context.Context, app string, params *AppsScaleParams) (*http.Response, error)
35+
AppsScale(ctx context.Context, app string, params *AppsScaleParams) ([]ContainerType, string, error)
3636
AppsForceHTTPS(ctx context.Context, name string, enable bool) (*App, error)
3737
AppsStickySession(ctx context.Context, name string, enable bool) (*App, error)
3838
AppsRouterLogs(ctx context.Context, name string, enable bool) (*App, error)
@@ -313,7 +313,12 @@ func (c *Client) AppsContainerTypes(ctx context.Context, app string) ([]Containe
313313
return containerTypesRes.Containers, nil
314314
}
315315

316-
func (c *Client) AppsScale(ctx context.Context, app string, params *AppsScaleParams) (*http.Response, error) {
316+
type ScaleRes struct {
317+
Containers []ContainerType `json:"containers"`
318+
}
319+
320+
// AppsScale scales an app and returns the updated containers and the operation URL when scaling is processed asynchronously.
321+
func (c *Client) AppsScale(ctx context.Context, app string, params *AppsScaleParams) ([]ContainerType, string, error) {
317322
req := &httpclient.APIRequest{
318323
Method: "POST",
319324
Endpoint: "/apps/" + app + "/scale",
@@ -322,9 +327,18 @@ func (c *Client) AppsScale(ctx context.Context, app string, params *AppsScalePar
322327
// Otherwise async job is triggered, it's 202
323328
Expected: httpclient.Statuses{200, 202},
324329
}
325-
var res *http.Response
326-
err := c.ScalingoAPI().DoRequest(ctx, req, &res)
327-
return res, err
330+
res, err := c.ScalingoAPI().Do(ctx, req)
331+
if err != nil {
332+
return nil, "", errors.Wrap(ctx, err, "request Scalingo API to scale the application")
333+
}
334+
335+
var scaleRes ScaleRes
336+
err = json.NewDecoder(res.Body).Decode(&scaleRes)
337+
if err != nil {
338+
return nil, "", errors.Wrapf(ctx, err, "decode API response to scale request")
339+
}
340+
341+
return scaleRes.Containers, res.Header.Get("Location"), nil
328342
}
329343

330344
func (c *Client) AppsForceHTTPS(ctx context.Context, name string, enable bool) (*App, error) {

http/httpmock/client_mock.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks_sig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"github.com/Scalingo/go-scalingo.AddonProvidersService": "f0 56 1c c9 ae 9b 6e a5 2f 98 fa 72 1f a2 f0 e6 a7 23 b4 4c",
44
"github.com/Scalingo/go-scalingo.AddonsService": "e5 fd 9a 36 39 fc 08 7d 37 ef 0d a9 5c a5 ba dc 53 db e8 39",
55
"github.com/Scalingo/go-scalingo.AlertsService": "31 44 7d d3 3f 5b 0b 61 26 03 79 65 a2 16 77 a1 66 66 e8 05",
6-
"github.com/Scalingo/go-scalingo.AppsService": "bd ac 01 ef a1 ae 45 1e b8 66 b7 d1 ec e3 71 31 c2 62 01 5f",
6+
"github.com/Scalingo/go-scalingo.AppsService": "22 f1 ba 14 dd 25 00 06 c4 2e 51 66 16 a1 15 3c ed 86 8b 93",
77
"github.com/Scalingo/go-scalingo.AutoscalersService": "9f cf 1b 7a dc 9d e3 d3 62 89 41 0f d4 30 83 28 7b 40 f1 72",
88
"github.com/Scalingo/go-scalingo.BackupsService": "66 59 74 49 68 65 69 e4 b0 97 8e a2 45 e6 ff fc 71 85 06 16",
99
"github.com/Scalingo/go-scalingo.CollaboratorsService": "c9 3a 93 de 00 2d e8 87 9c cc bd 3f f0 0e a1 48 78 a4 d7 3a",
@@ -29,6 +29,6 @@
2929
"github.com/Scalingo/go-scalingo.TokensService": "32 2d 05 42 b4 9c a9 3b 1b 6c ce 0e da 18 cf 6f 8f cb fc 2a",
3030
"github.com/Scalingo/go-scalingo.UsersService": "9e c5 75 1e aa 05 dd a7 a3 17 5f 4e 82 80 e2 34 55 a2 70 df",
3131
"github.com/Scalingo/go-scalingo.VariablesService": "8c d1 eb bc dc ab a9 7e 98 c5 8e 58 03 63 1f 35 5b f4 e6 2a",
32-
"github.com/Scalingo/go-scalingo/http.Client": "0d f4 50 e8 93 5c 37 01 f5 1b b9 90 eb bc 21 8c 03 19 81 a3",
32+
"github.com/Scalingo/go-scalingo/http.Client": "26 26 d6 21 12 7a b4 88 dc 46 fe 51 21 d6 00 94 94 a1 7f 89",
3333
"github.com/Scalingo/go-scalingo/http.TokensService": "e0 cf 0b 06 6f 07 a7 2b f2 c9 14 0f 3e aa d1 6b 83 5b 95 73"
3434
}

scalingomock/api_mock.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scalingomock/appsservice_mock.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)