@@ -23,18 +23,14 @@ const gatewaysFixture string = `
2323 "name": "example-go",
2424 "created": "2023-04-19T00:00:00UTC",
2525 "updated": "2023-04-19T00:00:00UTC",
26- "listeners ": [
26+ "ports ": [
2727 {
28- "name": "example-go-80-http",
2928 "port": 80,
30- "protocol": "HTTP",
31- "allowedRoutes": {"namespaces": {"from": "All"}}
29+ "protocol": "HTTP"
3230 },
3331 {
34- "name": "example-go-443-https",
3532 "port": 443,
36- "protocol": "HTTPS",
37- "allowedRoutes": {"namespaces": {"from": "All"}}
33+ "protocol": "HTTPS"
3834 }
3935 ],
4036 "addresses": [
@@ -48,8 +44,8 @@ const gatewaysFixture string = `
4844}`
4945
5046const (
51- gatewayCreateExpected string = `{"name":"example-go","port":443,"protocol":"HTTPS"}`
52- gatewayRemoveExpected string = `{"name":"example-go","port":443,"protocol":"HTTPS"}`
47+ gatewayApplyExpected string = `{"app":"example-go"," name":"example-go","ports":[{" port":80,"protocol":"HTTP"},{"port": 443,"protocol":"HTTPS"}] }`
48+ gatewayInfoResponse string = `{"name":"example-go","ports":[{" port":80,"protocol":"HTTP"},{"port": 443,"protocol":"HTTPS"}] }`
5349)
5450
5551type fakeHTTPServer struct {}
@@ -62,37 +58,31 @@ func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
6258 return
6359 }
6460
65- if req .URL .Path == "/v2/apps/example-go/gateways/" && req .Method == "POST " {
61+ if req .URL .Path == "/v2/apps/example-go/gateways/example-go/ " && req .Method == "PUT " {
6662 body , err := io .ReadAll (req .Body )
6763 if err != nil {
6864 fmt .Println (err )
6965 res .WriteHeader (http .StatusInternalServerError )
7066 res .Write (nil )
7167 }
72- if string (body ) != gatewayCreateExpected {
73- fmt .Printf ("Expected '%s', Got '%s'\n " , gatewayCreateExpected , body )
68+ if string (body ) != gatewayApplyExpected {
69+ fmt .Printf ("Expected '%s', Got '%s'\n " , gatewayApplyExpected , body )
7470 res .WriteHeader (http .StatusInternalServerError )
7571 res .Write (nil )
7672 return
7773 }
7874
79- res .WriteHeader (http .StatusCreated )
75+ res .WriteHeader (http .StatusOK )
76+ res .Write ([]byte (gatewayInfoResponse ))
8077 return
8178 }
8279
83- if req .URL .Path == "/v2/apps/example-go/gateways/" && req .Method == "DELETE" {
84- body , err := io .ReadAll (req .Body )
85- if err != nil {
86- fmt .Println (err )
87- res .WriteHeader (http .StatusInternalServerError )
88- res .Write (nil )
89- }
90- if string (body ) != gatewayRemoveExpected {
91- fmt .Printf ("Expected '%s', Got '%s'\n " , gatewayRemoveExpected , body )
92- res .WriteHeader (http .StatusInternalServerError )
93- res .Write (nil )
94- return
95- }
80+ if req .URL .Path == "/v2/apps/example-go/gateways/example-go/" && req .Method == "GET" {
81+ res .Write ([]byte (gatewayInfoResponse ))
82+ return
83+ }
84+
85+ if req .URL .Path == "/v2/apps/example-go/gateways/example-go/" && req .Method == "DELETE" {
9686 res .WriteHeader (http .StatusNoContent )
9787 return
9888 }
@@ -111,18 +101,14 @@ func TestGatewaysList(t *testing.T) {
111101 Created : "2023-04-19T00:00:00UTC" ,
112102 Name : "example-go" ,
113103 Updated : "2023-04-19T00:00:00UTC" ,
114- Listeners : []api.Listener {
104+ Ports : []api.GatewayPort {
115105 {
116- Name : "example-go-80-http" ,
117- Port : 80 ,
118- Protocol : "HTTP" ,
119- AllowedRoutes : map [string ]any {"namespaces" : map [string ]any {"from" : "All" }},
106+ Port : 80 ,
107+ Protocol : "HTTP" ,
120108 },
121109 {
122- Name : "example-go-443-https" ,
123- Port : 443 ,
124- Protocol : "HTTPS" ,
125- AllowedRoutes : map [string ]any {"namespaces" : map [string ]any {"from" : "All" }},
110+ Port : 443 ,
111+ Protocol : "HTTPS" ,
126112 },
127113 },
128114 Addresses : []api.Address {
@@ -152,7 +138,37 @@ func TestGatewaysList(t *testing.T) {
152138 }
153139}
154140
155- func TestGatewaysAdd (t * testing.T ) {
141+ func TestGatewaysApply (t * testing.T ) {
142+ t .Parallel ()
143+
144+ handler := fakeHTTPServer {}
145+ server := httptest .NewServer (handler )
146+ defer server .Close ()
147+
148+ drycc , err := drycc .New (false , server .URL , "abc" )
149+ if err != nil {
150+ t .Fatal (err )
151+ }
152+
153+ req := api.GatewayUpdateRequest {
154+ Name : "example-go" ,
155+ Ports : []api.GatewayPort {
156+ {Port : 80 , Protocol : "HTTP" },
157+ {Port : 443 , Protocol : "HTTPS" },
158+ },
159+ }
160+
161+ info , err := Apply (drycc , "example-go" , req )
162+ if err != nil {
163+ t .Fatal (err )
164+ }
165+
166+ if len (info .Ports ) != 2 {
167+ t .Fatalf ("Expected 2 ports, got %d" , len (info .Ports ))
168+ }
169+ }
170+
171+ func TestGatewaysInfo (t * testing.T ) {
156172 t .Parallel ()
157173
158174 handler := fakeHTTPServer {}
@@ -164,10 +180,14 @@ func TestGatewaysAdd(t *testing.T) {
164180 t .Fatal (err )
165181 }
166182
167- err = New (drycc , "example-go" , "example-go" , 443 , "HTTPS " )
183+ info , err := Info (drycc , "example-go" , "example-go" )
168184 if err != nil {
169185 t .Fatal (err )
170186 }
187+
188+ if len (info .Ports ) != 2 {
189+ t .Fatalf ("Expected 2 ports, got %d" , len (info .Ports ))
190+ }
171191}
172192
173193func TestGatewaysRemove (t * testing.T ) {
@@ -182,7 +202,7 @@ func TestGatewaysRemove(t *testing.T) {
182202 t .Fatal (err )
183203 }
184204
185- if err = Delete (drycc , "example-go" , "example-go" , 443 , "HTTPS" ); err != nil {
205+ if err = Delete (drycc , "example-go" , "example-go" ); err != nil {
186206 t .Fatal (err )
187207 }
188208}
0 commit comments