-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a wait flag to deploys create (#156)
- Loading branch information
1 parent
1473812
commit d92d330
Showing
9 changed files
with
267 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package deploy_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/renderinc/cli/pkg/client" | ||
"github.com/renderinc/cli/pkg/deploy" | ||
) | ||
|
||
func TestIsComplete(t *testing.T) { | ||
t.Run("handles nil status", func(t *testing.T) { | ||
assert.False(t, deploy.IsComplete(nil)) | ||
}) | ||
|
||
tests := map[client.DeployStatus]bool{ | ||
client.DeployStatusBuildFailed: true, | ||
client.DeployStatusBuildInProgress: false, | ||
client.DeployStatusCanceled: true, | ||
client.DeployStatusCreated: false, | ||
client.DeployStatusDeactivated: true, | ||
client.DeployStatusLive: true, | ||
client.DeployStatusPreDeployFailed: true, | ||
client.DeployStatusPreDeployInProgress: false, | ||
client.DeployStatusUpdateFailed: true, | ||
client.DeployStatusUpdateInProgress: false, | ||
} | ||
|
||
for status, expected := range tests { | ||
t.Run(string(status), func(t *testing.T) { | ||
actual := deploy.IsComplete(&status) | ||
assert.Equal(t, expected, actual) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package views_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/renderinc/cli/pkg/client" | ||
"github.com/renderinc/cli/pkg/tui/views" | ||
) | ||
|
||
func TestWaitForDeploy(t *testing.T) { | ||
getDeployCallCount := 0 | ||
setupTestServer(t, func() (int, string) { | ||
getDeployCallCount++ | ||
if getDeployCallCount == 1 { | ||
return http.StatusOK, fmt.Sprintf(deployRespTmpl, client.DeployStatusBuildInProgress) | ||
} | ||
|
||
return http.StatusOK, fmt.Sprintf(deployRespTmpl, client.DeployStatusLive) | ||
}) | ||
|
||
dep, err := views.WaitForDeploy(context.Background(), "some-service-id", "some-deploy-id") | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, client.DeployStatusLive, *dep.Status) | ||
assert.Equal(t, "some-deploy-id", dep.Id) | ||
} | ||
|
||
func setupTestServer(t *testing.T, handler func() (int, string)) *httptest.Server { | ||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Add("Content-Type", "application/json") | ||
|
||
code, resp := handler() | ||
w.WriteHeader(code) | ||
_, err := w.Write([]byte(resp)) | ||
require.NoError(t, err) | ||
})) | ||
|
||
require.NoError(t, os.Setenv("RENDER_API_KEY", "test-key")) | ||
require.NoError(t, os.Setenv("RENDER_HOST", s.URL)) | ||
|
||
return s | ||
} | ||
|
||
const deployRespTmpl = `{ | ||
"commit": { | ||
"createdAt": "2022-09-23T15:34:12Z", | ||
"id": "a21fb02cd25b7be602c5becf7fcbe6cdb9764db8", | ||
"message": "Merge pull request #3" | ||
}, | ||
"createdAt": "2024-12-03T17:02:30.548731Z", | ||
"finishedAt": "2024-12-03T17:04:01.515412Z", | ||
"id": "some-deploy-id", | ||
"status": "%s", | ||
"trigger": "api", | ||
"updatedAt": "2024-12-03T17:04:01.516462Z" | ||
}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters