...
1from typing import Generator, Tuple, Union
2
3from abstract_tests import HTTP, AmbassadorTest, Node, ServiceType
4from kat.harness import Query
5
6
7class GzipMinimumConfigTest(AmbassadorTest):
8 target: ServiceType
9
10 def init(self):
11 self.target = HTTP()
12
13 def config(self) -> Generator[Union[str, Tuple[Node, str]], None, None]:
14 yield self, self.format(
15 """
16---
17apiVersion: getambassador.io/v3alpha1
18kind: Module
19name: ambassador
20config:
21 gzip:
22 enabled: true
23"""
24 )
25 yield self, self.format(
26 """
27---
28apiVersion: getambassador.io/v3alpha1
29kind: Mapping
30name: {self.target.path.k8s}
31hostname: "*"
32prefix: /target/
33service: {self.target.path.fqdn}
34"""
35 )
36
37 def queries(self):
38 yield Query(self.url("target/"), headers={"Accept-Encoding": "gzip"}, expected=200)
39
40 def check(self):
41 assert self.results[0].headers["Content-Encoding"] == ["gzip"]
42
43
44class GzipTest(AmbassadorTest):
45 target: ServiceType
46
47 def init(self):
48 self.target = HTTP()
49
50 def config(self) -> Generator[Union[str, Tuple[Node, str]], None, None]:
51 yield self, self.format(
52 """
53---
54apiVersion: getambassador.io/v3alpha1
55kind: Module
56name: ambassador
57config:
58 gzip:
59 min_content_length: 32
60 window_bits: 15
61 content_type:
62 - text/plain
63"""
64 )
65 yield self, self.format(
66 """
67---
68apiVersion: getambassador.io/v3alpha1
69kind: Mapping
70name: {self.target.path.k8s}
71hostname: "*"
72prefix: /target/
73service: {self.target.path.fqdn}
74"""
75 )
76
77 def queries(self):
78 yield Query(self.url("target/"), headers={"Accept-Encoding": "gzip"}, expected=200)
79
80 def check(self):
81 assert self.results[0].headers["Content-Encoding"] == ["gzip"]
82
83
84class GzipNotSupportedContentTypeTest(AmbassadorTest):
85 target: ServiceType
86
87 def init(self):
88 self.target = HTTP()
89
90 def config(self) -> Generator[Union[str, Tuple[Node, str]], None, None]:
91 yield self, self.format(
92 """
93---
94apiVersion: getambassador.io/v3alpha1
95kind: Module
96name: ambassador
97config:
98 gzip:
99 min_content_length: 32
100 content_type:
101 - application/json
102"""
103 )
104 yield self, self.format(
105 """
106---
107apiVersion: getambassador.io/v3alpha1
108kind: Mapping
109name: {self.target.path.k8s}
110hostname: "*"
111prefix: /target/
112service: {self.target.path.fqdn}
113"""
114 )
115
116 def queries(self):
117 yield Query(self.url("target/"), headers={"Accept-Encoding": "gzip"}, expected=200)
118
119 def check(self):
120 assert "Content-Encoding" not in self.results[0].headers
View as plain text