@@ -15,6 +15,7 @@ func TestImagesService_List(t *testing.T) {
1515 opts ListOptions
1616 response string
1717 statusCode int
18+ expectedQuery map [string ]string
1819 want * ImagesResponse
1920 wantErr bool
2021 }{
@@ -43,7 +44,8 @@ func TestImagesService_List(t *testing.T) {
4344 }
4445 ]
4546 }` ,
46- statusCode : http .StatusOK ,
47+ statusCode : http .StatusOK ,
48+ expectedQuery : map [string ]string {},
4749 want : & ImagesResponse {
4850 Results : []ImageResponse {
4951 {
@@ -67,12 +69,106 @@ func TestImagesService_List(t *testing.T) {
6769 },
6870 wantErr : false ,
6971 },
72+ {
73+ name : "list images with limit" ,
74+ registryID : "reg-123" ,
75+ repositoryName : "repo-test" ,
76+ opts : ListOptions {
77+ Limit : intPtr (10 ),
78+ },
79+ response : `{
80+ "results": []
81+ }` ,
82+ statusCode : http .StatusOK ,
83+ expectedQuery : map [string ]string {"_limit" : "10" },
84+ want : & ImagesResponse {
85+ Results : []ImageResponse {},
86+ },
87+ wantErr : false ,
88+ },
89+ {
90+ name : "list images with offset" ,
91+ registryID : "reg-123" ,
92+ repositoryName : "repo-test" ,
93+ opts : ListOptions {
94+ Offset : intPtr (5 ),
95+ },
96+ response : `{
97+ "results": []
98+ }` ,
99+ statusCode : http .StatusOK ,
100+ expectedQuery : map [string ]string {"_offset" : "5" },
101+ want : & ImagesResponse {
102+ Results : []ImageResponse {},
103+ },
104+ wantErr : false ,
105+ },
106+ {
107+ name : "list images with sort" ,
108+ registryID : "reg-123" ,
109+ repositoryName : "repo-test" ,
110+ opts : ListOptions {
111+ Sort : strPtr ("pushed_at" ),
112+ },
113+ response : `{
114+ "results": []
115+ }` ,
116+ statusCode : http .StatusOK ,
117+ expectedQuery : map [string ]string {"_sort" : "pushed_at" },
118+ want : & ImagesResponse {
119+ Results : []ImageResponse {},
120+ },
121+ wantErr : false ,
122+ },
123+ {
124+ name : "list images with expand" ,
125+ registryID : "reg-123" ,
126+ repositoryName : "repo-test" ,
127+ opts : ListOptions {
128+ Expand : []string {"tags" , "manifest" },
129+ },
130+ response : `{
131+ "results": []
132+ }` ,
133+ statusCode : http .StatusOK ,
134+ expectedQuery : map [string ]string {"_expand" : "tags,manifest" },
135+ want : & ImagesResponse {
136+ Results : []ImageResponse {},
137+ },
138+ wantErr : false ,
139+ },
140+ {
141+ name : "list images with multiple options" ,
142+ registryID : "reg-123" ,
143+ repositoryName : "repo-test" ,
144+ opts : ListOptions {
145+ Limit : intPtr (20 ),
146+ Offset : intPtr (10 ),
147+ Sort : strPtr ("created_at" ),
148+ Expand : []string {"tags" },
149+ },
150+ response : `{
151+ "results": []
152+ }` ,
153+ statusCode : http .StatusOK ,
154+ expectedQuery : map [string ]string {
155+ "_limit" : "20" ,
156+ "_offset" : "10" ,
157+ "_sort" : "created_at" ,
158+ "_expand" : "tags" ,
159+ },
160+ want : & ImagesResponse {
161+ Results : []ImageResponse {},
162+ },
163+ wantErr : false ,
164+ },
70165 {
71166 name : "empty response" ,
72167 registryID : "reg-123" ,
73168 repositoryName : "repo-test" ,
74169 response : "" ,
75170 statusCode : http .StatusOK ,
171+ expectedQuery : map [string ]string {},
76172 want : nil ,
77173 wantErr : true ,
78174 },
@@ -82,6 +178,7 @@ func TestImagesService_List(t *testing.T) {
82178 repositoryName : "repo-test" ,
83179 response : `{"results": [{"digest": "sha256:123"` ,
84180 statusCode : http .StatusOK ,
181+ expectedQuery : map [string ]string {},
85182 want : nil ,
86183 wantErr : true ,
87184 },
@@ -91,6 +188,7 @@ func TestImagesService_List(t *testing.T) {
91188 repositoryName : "repo-test" ,
92189 response : `{"error": "internal server error"}` ,
93190 statusCode : http .StatusInternalServerError ,
191+ expectedQuery : map [string ]string {},
94192 want : nil ,
95193 wantErr : true ,
96194 },
@@ -100,6 +198,7 @@ func TestImagesService_List(t *testing.T) {
100198 repositoryName : "repo-test" ,
101199 response : `{"error": "unauthorized"}` ,
102200 statusCode : http .StatusUnauthorized ,
201+ expectedQuery : map [string ]string {},
103202 want : nil ,
104203 wantErr : true ,
105204 },
@@ -109,6 +208,7 @@ func TestImagesService_List(t *testing.T) {
109208 repositoryName : "repo-test" ,
110209 response : `{"error": "repository not found"}` ,
111210 statusCode : http .StatusNotFound ,
211+ expectedQuery : map [string ]string {},
112212 want : nil ,
113213 wantErr : true ,
114214 },
@@ -120,6 +220,12 @@ func TestImagesService_List(t *testing.T) {
120220 if r .Method != http .MethodGet {
121221 t .Errorf ("expected GET method, got %s" , r .Method )
122222 }
223+ query := r .URL .Query ()
224+ for key , expectedValue := range tt .expectedQuery {
225+ if actualValue := query .Get (key ); actualValue != expectedValue {
226+ t .Errorf ("expected query param %s=%s, got %s" , key , expectedValue , actualValue )
227+ }
228+ }
123229 w .Header ().Set ("Content-Type" , "application/json" )
124230 w .WriteHeader (tt .statusCode )
125231 w .Write ([]byte (tt .response ))
0 commit comments