Skip to content

Commit 63ffa35

Browse files
author
Fabio Stabile
committed
Check pipeline status after deploy
1 parent 64bde20 commit 63ffa35

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

internal/cmd/deploy/trigger.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ func runDeployTrigger(ctx context.Context, environmentName string, options *clio
9393
return fmt.Errorf("error retrieving the pipeline status: %w", err)
9494
}
9595

96+
if status == "failed" {
97+
return fmt.Errorf("Pipeline failed")
98+
}
99+
96100
fmt.Printf("Pipeline ended with %s\n", status)
97101
return nil
98102
}

internal/cmd/deploy/trigger_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ func TestDeploy(t *testing.T) {
4141
server: testTriggerServer(t),
4242
projectID: "correct",
4343
},
44+
"pipeline failed": {
45+
server: testTriggerServer(t),
46+
projectID: "failed",
47+
expectErr: true,
48+
},
4449
"pipeline fails": {
4550
server: testTriggerServer(t),
4651
projectID: "fails-bad-request",
@@ -82,7 +87,7 @@ func testTriggerServer(t *testing.T) *httptest.Server {
8287
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
8388
t.Helper()
8489
switch {
85-
case r.Method == http.MethodPost && (r.URL.Path == fmt.Sprintf(deployProjectEndpointTemplate, "correct") || r.URL.Path == fmt.Sprintf(deployProjectEndpointTemplate, "fails-wait-status")):
90+
case r.Method == http.MethodPost && (r.URL.Path == fmt.Sprintf(deployProjectEndpointTemplate, "correct") || r.URL.Path == fmt.Sprintf(deployProjectEndpointTemplate, "fails-wait-status") || r.URL.Path == fmt.Sprintf(deployProjectEndpointTemplate, "failed")):
8691
data, err := resources.EncodeResourceToJSON(&resources.DeployProject{
8792
ID: 1,
8893
URL: "http://example.com",
@@ -97,6 +102,13 @@ func testTriggerServer(t *testing.T) *httptest.Server {
97102
})
98103
require.NoError(t, err)
99104
w.Write(data)
105+
case r.Method == http.MethodGet && r.URL.Path == fmt.Sprintf(pipelineStatusEndpointTemplate, "failed", 1) && r.URL.Query().Get("environment") == "environmentName":
106+
data, err := resources.EncodeResourceToJSON(&resources.PipelineStatus{
107+
ID: 1,
108+
Status: "failed",
109+
})
110+
require.NoError(t, err)
111+
w.Write(data)
100112
case r.Method == http.MethodPost && r.URL.Path == fmt.Sprintf(deployProjectEndpointTemplate, "fails-bad-request"):
101113
respBody := `{"error": "Bad Request","message":"some bad request"}`
102114

0 commit comments

Comments
 (0)