Skip to content

Commit 0e3e32d

Browse files
authored
test(gzip): reach ingress (#9541)
1 parent 1bc20da commit 0e3e32d

File tree

1 file changed

+104
-10
lines changed

1 file changed

+104
-10
lines changed

test/e2e/settings/gzip.go

Lines changed: 104 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package settings
1818

1919
import (
2020
"fmt"
21+
"net/http"
2122
"strings"
2223

2324
"github.com/onsi/ginkgo/v2"
@@ -29,11 +30,27 @@ import (
2930
var _ = framework.DescribeSetting("gzip", func() {
3031
f := framework.NewDefaultFramework("gzip")
3132

33+
host := "gzip"
34+
35+
ginkgo.BeforeEach(func() {
36+
f.NewHttpbinDeployment()
37+
f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.Namespace, framework.HTTPBinService, 80, nil))
38+
})
39+
3240
ginkgo.It("should be disabled by default", func() {
3341
f.WaitForNginxConfiguration(
3442
func(cfg string) bool {
3543
return !strings.Contains(cfg, "gzip on;")
36-
})
44+
},
45+
)
46+
47+
f.HTTPTestClient().
48+
GET("/xml").
49+
WithHeader("Host", host).
50+
WithHeader("Accept-Encoding", "gzip").
51+
Expect().
52+
Status(http.StatusOK).
53+
ContentEncoding()
3754
})
3855

3956
ginkgo.It("should be enabled with default settings", func() {
@@ -50,7 +67,16 @@ var _ = framework.DescribeSetting("gzip", func() {
5067
strings.Contains(cfg, fmt.Sprintf("gzip_types %s;", defaultCfg.GzipTypes)) &&
5168
strings.Contains(cfg, "gzip_proxied any;") &&
5269
strings.Contains(cfg, "gzip_vary on;")
53-
})
70+
},
71+
)
72+
73+
f.HTTPTestClient().
74+
GET("/xml").
75+
WithHeader("Host", host).
76+
WithHeader("Accept-Encoding", "gzip").
77+
Expect().
78+
Status(http.StatusOK).
79+
ContentEncoding("gzip")
5480
})
5581

5682
ginkgo.It("should set gzip_comp_level to 4", func() {
@@ -61,7 +87,16 @@ var _ = framework.DescribeSetting("gzip", func() {
6187
func(cfg string) bool {
6288
return strings.Contains(cfg, "gzip on;") &&
6389
strings.Contains(cfg, "gzip_comp_level 4;")
64-
})
90+
},
91+
)
92+
93+
f.HTTPTestClient().
94+
GET("/xml").
95+
WithHeader("Host", host).
96+
WithHeader("Accept-Encoding", "gzip").
97+
Expect().
98+
Status(http.StatusOK).
99+
ContentEncoding("gzip")
65100
})
66101

67102
ginkgo.It("should set gzip_disable to msie6", func() {
@@ -72,28 +107,87 @@ var _ = framework.DescribeSetting("gzip", func() {
72107
func(cfg string) bool {
73108
return strings.Contains(cfg, "gzip on;") &&
74109
strings.Contains(cfg, `gzip_disable "msie6";`)
75-
})
110+
},
111+
)
112+
113+
f.HTTPTestClient().
114+
GET("/xml").
115+
WithHeader("Host", host).
116+
WithHeader("Accept-Encoding", "gzip").
117+
WithHeader("User-Agent", "Mozilla/4.8 [en] (Windows NT 5.1; U)").
118+
Expect().
119+
Status(http.StatusOK).
120+
ContentEncoding("gzip")
121+
122+
f.HTTPTestClient().
123+
GET("/xml").
124+
WithHeader("Host", host).
125+
WithHeader("Accept-Encoding", "gzip").
126+
WithHeader("User-Agent", "Mozilla/45.0 (compatible; MSIE 6.0; Windows NT 5.1)").
127+
Expect().
128+
Status(http.StatusOK).
129+
ContentEncoding()
76130
})
77131

78132
ginkgo.It("should set gzip_min_length to 100", func() {
79133
f.UpdateNginxConfigMapData("use-gzip", "true")
80134
f.UpdateNginxConfigMapData("gzip-min-length", "100")
135+
f.UpdateNginxConfigMapData("gzip-types", "application/octet-stream")
81136

82137
f.WaitForNginxConfiguration(
83138
func(cfg string) bool {
84139
return strings.Contains(cfg, "gzip on;") &&
85-
strings.Contains(cfg, "gzip_min_length 100;")
86-
})
140+
strings.Contains(cfg, "gzip_min_length 100;") &&
141+
strings.Contains(cfg, "gzip_types application/octet-stream;")
142+
},
143+
)
144+
145+
f.HTTPTestClient().
146+
GET("/bytes/99").
147+
WithHeader("Host", host).
148+
WithHeader("Accept-Encoding", "gzip").
149+
Expect().
150+
Status(http.StatusOK).
151+
ContentType("application/octet-stream").
152+
ContentEncoding()
153+
154+
f.HTTPTestClient().
155+
GET("/bytes/100").
156+
WithHeader("Host", host).
157+
WithHeader("Accept-Encoding", "gzip").
158+
Expect().
159+
Status(http.StatusOK).
160+
ContentType("application/octet-stream").
161+
ContentEncoding("gzip")
87162
})
88163

89-
ginkgo.It("should set gzip_types to application/javascript", func() {
164+
ginkgo.It("should set gzip_types to text/html", func() {
90165
f.UpdateNginxConfigMapData("use-gzip", "true")
91-
f.UpdateNginxConfigMapData("gzip-types", "application/javascript")
166+
f.UpdateNginxConfigMapData("gzip-types", "text/html")
92167

93168
f.WaitForNginxConfiguration(
94169
func(cfg string) bool {
95170
return strings.Contains(cfg, "gzip on;") &&
96-
strings.Contains(cfg, "gzip_types application/javascript;")
97-
})
171+
strings.Contains(cfg, "gzip_types text/html;")
172+
},
173+
)
174+
175+
f.HTTPTestClient().
176+
GET("/xml").
177+
WithHeader("Host", host).
178+
WithHeader("Accept-Encoding", "gzip").
179+
Expect().
180+
Status(http.StatusOK).
181+
ContentType("application/xml").
182+
ContentEncoding()
183+
184+
f.HTTPTestClient().
185+
GET("/html").
186+
WithHeader("Host", host).
187+
WithHeader("Accept-Encoding", "gzip").
188+
Expect().
189+
Status(http.StatusOK).
190+
ContentType("text/html").
191+
ContentEncoding("gzip")
98192
})
99193
})

0 commit comments

Comments
 (0)