Skip to content

Commit

Permalink
Merge branch 'main' into create-database-firewall-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsomething authored Nov 19, 2024
2 parents c5f4a17 + 45ad288 commit c80884e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apps.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type AppsService interface {
Delete(ctx context.Context, appID string) (*Response, error)
Propose(ctx context.Context, propose *AppProposeRequest) (*AppProposeResponse, *Response, error)

Restart(ctx context.Context, appID string, opts *AppRestartRequest) (*Deployment, *Response, error)
GetDeployment(ctx context.Context, appID, deploymentID string) (*Deployment, *Response, error)
ListDeployments(ctx context.Context, appID string, opts *ListOptions) ([]*Deployment, *Response, error)
CreateDeployment(ctx context.Context, appID string, create ...*DeploymentCreateRequest) (*Deployment, *Response, error)
Expand Down Expand Up @@ -95,6 +96,11 @@ type DeploymentCreateRequest struct {
ForceBuild bool `json:"force_build"`
}

// AppRestartRequest represents a request to restart an app.
type AppRestartRequest struct {
Components []string `json:"components"`
}

// AlertDestinationUpdateRequest represents a request to update alert destinations.
type AlertDestinationUpdateRequest struct {
Emails []string `json:"emails"`
Expand Down Expand Up @@ -285,6 +291,22 @@ func (s *AppsServiceOp) Propose(ctx context.Context, propose *AppProposeRequest)
return res, resp, nil
}

// Restart restarts an app.
func (s *AppsServiceOp) Restart(ctx context.Context, appID string, opts *AppRestartRequest) (*Deployment, *Response, error) {
path := fmt.Sprintf("%s/%s/restart", appsBasePath, appID)

req, err := s.client.NewRequest(ctx, http.MethodPost, path, opts)
if err != nil {
return nil, nil, err
}
root := new(deploymentRoot)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Deployment, resp, nil
}

// GetDeployment gets an app deployment.
func (s *AppsServiceOp) GetDeployment(ctx context.Context, appID, deploymentID string) (*Deployment, *Response, error) {
path := fmt.Sprintf("%s/%s/deployments/%s", appsBasePath, appID, deploymentID)
Expand Down
40 changes: 40 additions & 0 deletions apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,46 @@ func TestApps_ProposeApp(t *testing.T) {
assert.True(t, res.AppNameAvailable)
}

func TestApps_Restart(t *testing.T) {
for _, tc := range []struct {
name string
components []string
}{
{
name: "all",
components: nil,
},
{
name: "specific",
components: []string{"service1", "service2"},
},
} {
t.Run(tc.name, func(t *testing.T) {
setup()
defer teardown()

ctx := context.Background()

mux.HandleFunc(fmt.Sprintf("/v2/apps/%s/restart", testApp.ID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)

var req AppRestartRequest
err := json.NewDecoder(r.Body).Decode(&req)
require.NoError(t, err)
assert.Equal(t, tc.components, req.Components)

json.NewEncoder(w).Encode(&deploymentRoot{Deployment: &testDeployment})
})

deployment, _, err := client.Apps.Restart(ctx, testApp.ID, &AppRestartRequest{
Components: tc.components,
})
require.NoError(t, err)
assert.Equal(t, &testDeployment, deployment)
})
}
}

func TestApps_CreateDeployment(t *testing.T) {
for _, forceBuild := range []bool{true, false} {
t.Run(fmt.Sprintf("ForceBuild_%t", forceBuild), func(t *testing.T) {
Expand Down

0 comments on commit c80884e

Please sign in to comment.