Skip to content

Commit

Permalink
Add an integration test for the console (web) command
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Jan 9, 2025
1 parent 2a3b045 commit 1fc0685
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions go-tests/web_console_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package tests

import (
"net/http/httptest"
"testing"

"github.com/platformsh/cli/pkg/mockapi"
"github.com/stretchr/testify/assert"
)

func TestWebConsole(t *testing.T) {
authServer := mockapi.NewAuthServer(t)
defer authServer.Close()

apiHandler := mockapi.NewHandler(t)
apiServer := httptest.NewServer(apiHandler)
defer apiServer.Close()

projectID := mockapi.ProjectID()
orgID := "org-" + mockapi.NumericID()

apiHandler.SetOrgs([]*mockapi.Org{
makeOrg(orgID, "cli-tests", "CLI Test Org", "my-user-id"),
})

apiHandler.SetProjects([]*mockapi.Project{{
ID: projectID,
Links: mockapi.MakeHALLinks("self=/projects/"+projectID,
"environments=/projects/"+projectID+"/environments"),
DefaultBranch: "main",
Organization: orgID,
}})
apiHandler.SetEnvironments([]*mockapi.Environment{
makeEnv(projectID, "main", "production", "active", nil),
})

f := newCommandFactory(t, apiServer.URL, authServer.URL)

assert.Equal(t, "https://console.cli-tests.example.com\n", f.Run("console", "--browser", "0"))

assert.Equal(t, "https://console.cli-tests.example.com/cli-tests/"+projectID+"\n",
f.Run("console", "--browser", "0", "-p", projectID))

assert.Equal(t, "https://console.cli-tests.example.com/cli-tests/"+projectID+"/main\n",
f.Run("console", "--browser", "0", "-p", projectID, "-e", "."))

// The "console" command should be aliased to "web".
assert.Equal(t, "https://console.cli-tests.example.com\n", f.Run("web", "--browser", "0"))
}

0 comments on commit 1fc0685

Please sign in to comment.