Skip to content

Commit

Permalink
Merge branch 'main' into ntate/apps/image-source
Browse files Browse the repository at this point in the history
  • Loading branch information
bentranter authored Nov 5, 2020
2 parents f6025d6 + f3e2fed commit 2ccdb0c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
17 changes: 14 additions & 3 deletions apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type AppsService interface {

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) (*Deployment, *Response, error)
CreateDeployment(ctx context.Context, appID string, create ...*DeploymentCreateRequest) (*Deployment, *Response, error)

GetLogs(ctx context.Context, appID, deploymentID, component string, logType AppLogType, follow bool) (*AppLogs, *Response, error)

Expand Down Expand Up @@ -62,6 +62,11 @@ type AppUpdateRequest struct {
Spec *AppSpec `json:"spec"`
}

// DeploymentCreateRequest represents a request to create a deployment.
type DeploymentCreateRequest struct {
ForceBuild bool `json:"force_build"`
}

type appRoot struct {
App *App `json:"app"`
}
Expand Down Expand Up @@ -210,9 +215,15 @@ func (s *AppsServiceOp) ListDeployments(ctx context.Context, appID string, opts
}

// CreateDeployment creates an app deployment.
func (s *AppsServiceOp) CreateDeployment(ctx context.Context, appID string) (*Deployment, *Response, error) {
func (s *AppsServiceOp) CreateDeployment(ctx context.Context, appID string, create ...*DeploymentCreateRequest) (*Deployment, *Response, error) {
path := fmt.Sprintf("%s/%s/deployments", appsBasePath, appID)
req, err := s.client.NewRequest(ctx, http.MethodPost, path, nil)

var createReq *DeploymentCreateRequest
for _, c := range create {
createReq = c
}

req, err := s.client.NewRequest(ctx, http.MethodPost, path, createReq)
if err != nil {
return nil, nil, err
}
Expand Down
39 changes: 25 additions & 14 deletions apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,31 @@ func TestApps_DeleteApp(t *testing.T) {
}

func TestApps_CreateDeployment(t *testing.T) {
setup()
defer teardown()

ctx := context.Background()

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

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

deployment, _, err := client.Apps.CreateDeployment(ctx, testApp.ID)
require.NoError(t, err)
assert.Equal(t, &testDeployment, deployment)
for _, forceBuild := range []bool{true, false} {
t.Run(fmt.Sprintf("ForceBuild_%t", forceBuild), func(t *testing.T) {
setup()
defer teardown()

ctx := context.Background()

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

var req DeploymentCreateRequest
err := json.NewDecoder(r.Body).Decode(&req)
require.NoError(t, err)
assert.Equal(t, forceBuild, req.ForceBuild)

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

deployment, _, err := client.Apps.CreateDeployment(ctx, testApp.ID, &DeploymentCreateRequest{
ForceBuild: forceBuild,
})
require.NoError(t, err)
assert.Equal(t, &testDeployment, deployment)
})
}
}

func TestApps_GetDeployment(t *testing.T) {
Expand Down

0 comments on commit 2ccdb0c

Please sign in to comment.