-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathproject_info_test.go
84 lines (67 loc) · 2.22 KB
/
project_info_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package tests
import (
"net/http/httptest"
"net/url"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/platformsh/cli/pkg/mockapi"
)
func TestProjectInfo(t *testing.T) {
authServer := mockapi.NewAuthServer(t)
defer authServer.Close()
myUserID := "my-user-id"
vendor := "test-vendor"
apiHandler := mockapi.NewHandler(t)
apiHandler.SetMyUser(&mockapi.User{ID: myUserID})
apiServer := httptest.NewServer(apiHandler)
defer apiServer.Close()
apiHandler.SetOrgs([]*mockapi.Org{
makeOrg("org-id-1", "org-1", "Org 1", myUserID),
})
projectID := mockapi.ProjectID()
created, err := time.Parse(time.RFC3339, "2014-04-01T10:00:00+01:00")
require.NoError(t, err)
apiHandler.SetProjects([]*mockapi.Project{
{
ID: projectID,
Title: "Project 1",
Region: "region-1",
Organization: "org-id-1",
Vendor: vendor,
Repository: mockapi.ProjectRepository{
URL: "git@git.region-1.example.com:mock-project.git",
},
DefaultBranch: "main",
CreatedAt: created,
UpdatedAt: created.Add(time.Second * 86400),
Links: mockapi.MakeHALLinks(
"self=/projects/"+url.PathEscape(projectID),
"#edit=/projects/"+url.PathEscape(projectID),
),
},
})
f := newCommandFactory(t, apiServer.URL, authServer.URL)
expectedLines := `Property Value
id ` + projectID + `
title Project 1
region region-1
organization org-id-1
vendor test-vendor
repository url: 'git@git.region-1.example.com:mock-project.git'
default_branch main
created_at 2014-04-01T09:00:00+00:00
updated_at 2014-04-02T09:00:00+00:00
git git@git.region-1.example.com:mock-project.git`
output := f.Run("pro:info", "-p", projectID, "--format", "plain", "--refresh")
for _, line := range strings.Split(expectedLines, "\n") {
assert.True(t, strings.Contains(output, line+"\n"))
}
assert.Equal(t, "2014-04-01\n", f.Run("pro:info", "-p", projectID, "created_at", "--date-fmt", "Y-m-d"))
assert.Equal(t, "Project 1\n", f.Run("pro:info", "-p", projectID, "title"))
f.Run("pro:info", "-v", "-p", projectID, "title", "New Title")
// TODO --refresh should not be needed here
assert.Equal(t, "New Title\n", f.Run("pro:info", "-p", projectID, "title", "--refresh"))
}