Skip to content

Commit 25a14f4

Browse files
committed
feat: meta field implemented in all container register listing responses
1 parent cbfeb96 commit 25a14f4

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

containerregistry/commons.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package containerregistry
2+
3+
type (
4+
Meta struct {
5+
Page Page `json:"page"`
6+
}
7+
8+
Page struct {
9+
Count int `json:"count"`
10+
Limit int `json:"limit"`
11+
Offset int `json:"offset"`
12+
Total int `json:"total"`
13+
}
14+
)

containerregistry/images.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type (
1818

1919
// ImagesResponse represents the response when listing images
2020
ImagesResponse struct {
21+
Meta Meta `json:"meta"`
2122
Results []ImageResponse `json:"results"`
2223
}
2324

containerregistry/registries.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type (
4545
// ListRegistriesResponse represents the response when listing registries
4646
ListRegistriesResponse struct {
4747
Registries []RegistryResponse `json:"results"`
48+
Meta Meta `json:"meta"`
4849
}
4950

5051
// registriesService implements the RegistriesService interface

containerregistry/repositories.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ type (
3434

3535
// RepositoriesResponse represents the response when listing repositories
3636
RepositoriesResponse struct {
37-
Goal AmountRepositoryResponse `json:"goal"`
38-
Results []RepositoryResponse `json:"results"`
37+
Meta Meta `json:"meta"`
38+
Results []RepositoryResponse `json:"results"`
3939
}
4040

4141
// repositoriesService implements the RepositoriesService interface

containerregistry/repositories_test.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ func TestRepositoriesService_List(t *testing.T) {
2121
name: "successful list repositories",
2222
registryID: "reg-123",
2323
response: `{
24-
"goal": {
25-
"total": 2
24+
"meta": {
25+
"page": {
26+
"count": 2,
27+
"limit": 0,
28+
"offset": 0,
29+
"total": 2
30+
}
2631
},
2732
"results": [
2833
{
@@ -43,7 +48,7 @@ func TestRepositoriesService_List(t *testing.T) {
4348
}`,
4449
statusCode: http.StatusOK,
4550
want: &RepositoriesResponse{
46-
Goal: AmountRepositoryResponse{Total: 2},
51+
Meta: Meta{Page: Page{Count: 2, Limit: 0, Offset: 0, Total: 2}},
4752
Results: []RepositoryResponse{
4853
{
4954
RegistryName: "test-registry",
@@ -111,7 +116,14 @@ func TestRepositoriesService_List(t *testing.T) {
111116
Offset: intPtr(20),
112117
},
113118
response: `{
114-
"goal": {"total": 30},
119+
"meta": {
120+
"page": {
121+
"count": 1,
122+
"limit": 10,
123+
"offset": 20,
124+
"total": 30
125+
}
126+
},
115127
"results": [
116128
{
117129
"registry_name": "test-registry",
@@ -124,7 +136,7 @@ func TestRepositoriesService_List(t *testing.T) {
124136
}`,
125137
statusCode: http.StatusOK,
126138
want: &RepositoriesResponse{
127-
Goal: AmountRepositoryResponse{Total: 30},
139+
Meta: Meta{Page: Page{Count: 1, Limit: 10, Offset: 20, Total: 30}},
128140
Results: []RepositoryResponse{
129141
{
130142
RegistryName: "test-registry",
@@ -144,7 +156,14 @@ func TestRepositoriesService_List(t *testing.T) {
144156
Sort: strPtr("name:asc"),
145157
},
146158
response: `{
147-
"goal": {"total": 1},
159+
"meta": {
160+
"page": {
161+
"count": 1,
162+
"limit": 0,
163+
"offset": 0,
164+
"total": 1
165+
}
166+
},
148167
"results": [
149168
{
150169
"registry_name": "test-registry",
@@ -157,7 +176,7 @@ func TestRepositoriesService_List(t *testing.T) {
157176
}`,
158177
statusCode: http.StatusOK,
159178
want: &RepositoriesResponse{
160-
Goal: AmountRepositoryResponse{Total: 1},
179+
Meta: Meta{Page: Page{Count: 1, Limit: 0, Offset: 0, Total: 1}},
161180
Results: []RepositoryResponse{
162181
{
163182
RegistryName: "test-registry",
@@ -195,8 +214,8 @@ func TestRepositoriesService_List(t *testing.T) {
195214
if len(got.Results) != len(tt.want.Results) {
196215
t.Errorf("List() got %v results, want %v", len(got.Results), len(tt.want.Results))
197216
}
198-
if got.Goal.Total != tt.want.Goal.Total {
199-
t.Errorf("List() got total %v, want %v", got.Goal.Total, tt.want.Goal.Total)
217+
if got.Meta.Page.Total != tt.want.Meta.Page.Total {
218+
t.Errorf("List() got total %v, want %v", got.Meta.Page.Total, tt.want.Meta.Page.Total)
200219
}
201220
}
202221
})
@@ -363,7 +382,7 @@ func TestRepositoriesService_Concurrent(t *testing.T) {
363382
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
364383
w.Header().Set("Content-Type", "application/json")
365384
w.WriteHeader(http.StatusOK)
366-
w.Write([]byte(`{"goal": {"total": 0}, "results": []}`))
385+
w.Write([]byte(`{"meta": {"page": {"count": 0, "limit": 0, "offset": 0, "total": 0}}, "results": []}`))
367386
}))
368387
defer server.Close()
369388

0 commit comments

Comments
 (0)