apps: Support pagination. (#443)
This commit is contained in:
parent
dd4bfeaea9
commit
6e8018121d
34
apps.go
34
apps.go
|
@ -73,7 +73,9 @@ type appRoot struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type appsRoot struct {
|
type appsRoot struct {
|
||||||
Apps []*App `json:"apps"`
|
Apps []*App `json:"apps"`
|
||||||
|
Links *Links `json:"links"`
|
||||||
|
Meta *Meta `json:"meta"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type deploymentRoot struct {
|
type deploymentRoot struct {
|
||||||
|
@ -82,6 +84,8 @@ type deploymentRoot struct {
|
||||||
|
|
||||||
type deploymentsRoot struct {
|
type deploymentsRoot struct {
|
||||||
Deployments []*Deployment `json:"deployments"`
|
Deployments []*Deployment `json:"deployments"`
|
||||||
|
Links *Links `json:"links"`
|
||||||
|
Meta *Meta `json:"meta"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type appTierRoot struct {
|
type appTierRoot struct {
|
||||||
|
@ -143,6 +147,11 @@ func (s *AppsServiceOp) Get(ctx context.Context, appID string) (*App, *Response,
|
||||||
// List apps.
|
// List apps.
|
||||||
func (s *AppsServiceOp) List(ctx context.Context, opts *ListOptions) ([]*App, *Response, error) {
|
func (s *AppsServiceOp) List(ctx context.Context, opts *ListOptions) ([]*App, *Response, error) {
|
||||||
path := appsBasePath
|
path := appsBasePath
|
||||||
|
path, err := addOptions(path, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
|
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -152,6 +161,15 @@ func (s *AppsServiceOp) List(ctx context.Context, opts *ListOptions) ([]*App, *R
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, resp, err
|
return nil, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if l := root.Links; l != nil {
|
||||||
|
resp.Links = l
|
||||||
|
}
|
||||||
|
|
||||||
|
if m := root.Meta; m != nil {
|
||||||
|
resp.Meta = m
|
||||||
|
}
|
||||||
|
|
||||||
return root.Apps, resp, nil
|
return root.Apps, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,6 +237,11 @@ func (s *AppsServiceOp) GetDeployment(ctx context.Context, appID, deploymentID s
|
||||||
// ListDeployments lists an app deployments.
|
// ListDeployments lists an app deployments.
|
||||||
func (s *AppsServiceOp) ListDeployments(ctx context.Context, appID string, opts *ListOptions) ([]*Deployment, *Response, error) {
|
func (s *AppsServiceOp) ListDeployments(ctx context.Context, appID string, opts *ListOptions) ([]*Deployment, *Response, error) {
|
||||||
path := fmt.Sprintf("%s/%s/deployments", appsBasePath, appID)
|
path := fmt.Sprintf("%s/%s/deployments", appsBasePath, appID)
|
||||||
|
path, err := addOptions(path, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
|
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -228,6 +251,15 @@ func (s *AppsServiceOp) ListDeployments(ctx context.Context, appID string, opts
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, resp, err
|
return nil, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if l := root.Links; l != nil {
|
||||||
|
resp.Links = l
|
||||||
|
}
|
||||||
|
|
||||||
|
if m := root.Meta; m != nil {
|
||||||
|
resp.Meta = m
|
||||||
|
}
|
||||||
|
|
||||||
return root.Deployments, resp, nil
|
return root.Deployments, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
apps_test.go
16
apps_test.go
|
@ -217,12 +217,16 @@ func TestApps_ListApp(t *testing.T) {
|
||||||
mux.HandleFunc("/v2/apps", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/v2/apps", func(w http.ResponseWriter, r *http.Request) {
|
||||||
testMethod(t, r, http.MethodGet)
|
testMethod(t, r, http.MethodGet)
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(&appsRoot{Apps: []*App{&testApp}})
|
json.NewEncoder(w).Encode(&appsRoot{Apps: []*App{&testApp}, Meta: &Meta{Total: 1}, Links: &Links{}})
|
||||||
})
|
})
|
||||||
|
|
||||||
apps, _, err := client.Apps.List(ctx, nil)
|
apps, resp, err := client.Apps.List(ctx, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, []*App{&testApp}, apps)
|
assert.Equal(t, []*App{&testApp}, apps)
|
||||||
|
assert.Equal(t, 1, resp.Meta.Total)
|
||||||
|
currentPage, err := resp.Links.CurrentPage()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, 1, currentPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestApps_UpdateApp(t *testing.T) {
|
func TestApps_UpdateApp(t *testing.T) {
|
||||||
|
@ -375,12 +379,16 @@ func TestApps_ListDeployments(t *testing.T) {
|
||||||
mux.HandleFunc(fmt.Sprintf("/v2/apps/%s/deployments", testApp.ID), func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc(fmt.Sprintf("/v2/apps/%s/deployments", testApp.ID), func(w http.ResponseWriter, r *http.Request) {
|
||||||
testMethod(t, r, http.MethodGet)
|
testMethod(t, r, http.MethodGet)
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(&deploymentsRoot{Deployments: []*Deployment{&testDeployment}})
|
json.NewEncoder(w).Encode(&deploymentsRoot{Deployments: []*Deployment{&testDeployment}, Meta: &Meta{Total: 1}, Links: &Links{}})
|
||||||
})
|
})
|
||||||
|
|
||||||
deployments, _, err := client.Apps.ListDeployments(ctx, testApp.ID, nil)
|
deployments, resp, err := client.Apps.ListDeployments(ctx, testApp.ID, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, []*Deployment{&testDeployment}, deployments)
|
assert.Equal(t, []*Deployment{&testDeployment}, deployments)
|
||||||
|
assert.Equal(t, 1, resp.Meta.Total)
|
||||||
|
currentPage, err := resp.Links.CurrentPage()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, 1, currentPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestApps_GetLogs(t *testing.T) {
|
func TestApps_GetLogs(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue