-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the app:config and mount:list commands
Test the mount:list command
- Loading branch information
1 parent
31c7381
commit 52f22e4
Showing
3 changed files
with
184 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package tests | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/platformsh/cli/internal/mockapi" | ||
) | ||
|
||
func TestAppConfig(t *testing.T) { | ||
authServer := mockapi.NewAuthServer(t) | ||
defer authServer.Close() | ||
|
||
apiHandler := mockapi.NewHandler(t) | ||
|
||
projectID := "aht1iegh3nei9" | ||
|
||
apiHandler.SetProjects([]*mockapi.Project{{ | ||
ID: projectID, | ||
Links: mockapi.MakeHALLinks("self=/projects/"+projectID, | ||
"environments=/projects/"+projectID+"/environments"), | ||
DefaultBranch: "main", | ||
}}) | ||
|
||
main := makeEnv(projectID, "main", "production", "active", nil) | ||
main.SetCurrentDeployment(&mockapi.Deployment{ | ||
WebApps: map[string]mockapi.App{ | ||
"app": {Name: "app", Type: "golang:1.23", Size: "M", Disk: 2048, Mounts: map[string]mockapi.Mount{}}, | ||
}, | ||
Links: mockapi.MakeHALLinks("self=/projects/" + projectID + "/environments/main/deployment/current"), | ||
}) | ||
envs := []*mockapi.Environment{main} | ||
|
||
apiHandler.SetEnvironments(envs) | ||
|
||
apiServer := httptest.NewServer(apiHandler) | ||
defer apiServer.Close() | ||
|
||
run := runnerWithAuth(t, apiServer.URL, authServer.URL) | ||
|
||
assert.Equal(t, strings.TrimLeft(` | ||
name: app | ||
type: 'golang:1.23' | ||
size: M | ||
disk: 2048 | ||
mounts: { } | ||
`, "\n"), run("app:config", "-p", projectID, "-e", ".", "--refresh")) | ||
|
||
assert.Equal(t, "golang:1.23\n", run("app:config", "-p", projectID, "-e", ".", "--refresh", "-P", "type")) | ||
} | ||
|
||
func TestAppConfigLocal(t *testing.T) { | ||
run := runWithLocalApp(t, &mockapi.App{ | ||
Name: "local-app", | ||
Type: "golang:1.24", | ||
Size: "L", | ||
Disk: 1024, | ||
Mounts: map[string]mockapi.Mount{ | ||
"example": { | ||
Source: "local", | ||
SourcePath: "example", | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Equal(t, strings.TrimLeft(` | ||
name: local-app | ||
type: 'golang:1.24' | ||
size: L | ||
disk: 1024 | ||
mounts: | ||
example: | ||
source: local | ||
source_path: example | ||
`, "\n"), run("app:config")) | ||
|
||
assert.Equal(t, "local\n", run("app:config", "--property", "mounts.example.source")) | ||
} | ||
|
||
func runWithLocalApp(t *testing.T, app *mockapi.App) func(args ...string) string { | ||
return func(args ...string) string { | ||
j, err := json.Marshal(app) | ||
require.NoError(t, err) | ||
cmd := command(t, args...) | ||
cmd.Env = append(cmd.Env, "PLATFORM_APPLICATION="+base64.StdEncoding.EncodeToString(j)) | ||
b, err := cmd.Output() | ||
require.NoError(t, err) | ||
return string(b) | ||
} | ||
} |
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,80 @@ | ||
package tests | ||
|
||
import ( | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/platformsh/cli/internal/mockapi" | ||
) | ||
|
||
func TestMountList(t *testing.T) { | ||
authServer := mockapi.NewAuthServer(t) | ||
defer authServer.Close() | ||
|
||
apiHandler := mockapi.NewHandler(t) | ||
|
||
apiServer := httptest.NewServer(apiHandler) | ||
defer apiServer.Close() | ||
|
||
projectID := "oa3chu0foot4s" | ||
|
||
apiHandler.SetProjects([]*mockapi.Project{{ | ||
ID: projectID, | ||
Links: mockapi.MakeHALLinks("self=/projects/"+projectID, | ||
"environments=/projects/"+projectID+"/environments"), | ||
DefaultBranch: "main", | ||
}}) | ||
|
||
main := makeEnv(projectID, "main", "production", "active", nil) | ||
main.Links["pf:ssh:app"] = mockapi.HALLink{HREF: "ssh://" + projectID + "--app@ssh.example.com"} | ||
main.SetCurrentDeployment(&mockapi.Deployment{ | ||
WebApps: map[string]mockapi.App{ | ||
"app": { | ||
Name: "app", | ||
Type: "golang:1.23", | ||
Size: "AUTO", | ||
Mounts: map[string]mockapi.Mount{ | ||
"/public/sites/default/files": {Source: "local", SourcePath: "files"}, | ||
}}, | ||
}, | ||
Services: map[string]mockapi.App{}, | ||
Routes: map[string]any{}, | ||
Workers: map[string]mockapi.Worker{}, | ||
Links: mockapi.MakeHALLinks("self=/projects/" + projectID + "/environments/main/deployment/current"), | ||
}) | ||
|
||
apiHandler.SetEnvironments([]*mockapi.Environment{main}) | ||
|
||
run := runnerWithAuth(t, apiServer.URL, authServer.URL) | ||
|
||
assert.Equal(t, strings.TrimLeft(` | ||
Mount path Definition | ||
public/sites/default/files "source: local | ||
source_path: files" | ||
`, "\n"), run("mounts", "-p", projectID, "-e", "main", "--refresh", "--format", "tsv")) | ||
|
||
assert.Equal(t, "public/sites/default/files\n", run("mounts", "-p", projectID, "-e", "main", "--paths")) | ||
} | ||
|
||
func TestMountListLocal(t *testing.T) { | ||
run := runWithLocalApp(t, &mockapi.App{ | ||
Name: "local-app", | ||
Type: "golang:1.24", | ||
Size: "L", | ||
Mounts: map[string]mockapi.Mount{ | ||
"/tmp": {Source: "local", SourcePath: "tmp"}, | ||
}, | ||
}) | ||
|
||
assert.Equal(t, strings.TrimLeft(` | ||
+------------+------------------+ | ||
| Mount path | Definition | | ||
+------------+------------------+ | ||
| tmp | source: local | | ||
| | source_path: tmp | | ||
+------------+------------------+ | ||
`, "\n"), run("mounts")) | ||
} |