Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 70d1e94

Browse files
authored
refactor e2e (#85)
Signed-off-by: mathetake <[email protected]>
1 parent 7e46268 commit 70d1e94

File tree

2 files changed

+47
-65
lines changed

2 files changed

+47
-65
lines changed

e2e/e2e_test.go

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"net/http"
2323
"os"
2424
"os/exec"
25-
"strings"
2625
"testing"
2726
"time"
2827

@@ -63,8 +62,8 @@ func TestE2E_helloworld(t *testing.T) {
6362

6463
out := stdErr.String()
6564
fmt.Println(out)
66-
assert.True(t, strings.Contains(out, "wasm log helloworld: proxy_on_vm_start from Go!"))
67-
assert.True(t, strings.Contains(out, "wasm log helloworld: It's"))
65+
assert.Contains(t, out, "wasm log helloworld: proxy_on_vm_start from Go!")
66+
assert.Contains(t, out, "wasm log helloworld: It's")
6867
}
6968

7069
func TestE2E_http_auth_random(t *testing.T) {
@@ -88,9 +87,9 @@ func TestE2E_http_auth_random(t *testing.T) {
8887

8988
out := stdErr.String()
9089
fmt.Println(out)
91-
assert.True(t, strings.Contains(out, "access forbidden"))
92-
assert.True(t, strings.Contains(out, "access granted"))
93-
assert.True(t, strings.Contains(out, "response header from httpbin: :status: 200"))
90+
assert.Contains(t, out, "access forbidden")
91+
assert.Contains(t, out, "access granted")
92+
assert.Contains(t, out, "response header from httpbin: :status: 200")
9493
}
9594

9695
func TestE2E_http_headers(t *testing.T) {
@@ -112,9 +111,9 @@ func TestE2E_http_headers(t *testing.T) {
112111

113112
out := stdErr.String()
114113
fmt.Println(out)
115-
assert.True(t, strings.Contains(out, key))
116-
assert.True(t, strings.Contains(out, value))
117-
assert.True(t, strings.Contains(out, "server: envoy"))
114+
assert.Contains(t, out, key)
115+
assert.Contains(t, out, value)
116+
assert.Contains(t, out, "server: envoy")
118117
}
119118

120119
func TestE2E_http_body(t *testing.T) {
@@ -123,7 +122,7 @@ func TestE2E_http_body(t *testing.T) {
123122
require.NoError(t, cmd.Process.Kill())
124123
}()
125124

126-
req, err := http.NewRequest("GET", envoyEndpoint, bytes.NewBuffer([]byte(`{ "example": "body" }`)))
125+
req, err := http.NewRequest("GET", envoyEndpoint+"/anything", bytes.NewBuffer([]byte(`{ "example": "body" }`)))
127126
require.NoError(t, err)
128127

129128
r, err := http.DefaultClient.Do(req)
@@ -132,11 +131,15 @@ func TestE2E_http_body(t *testing.T) {
132131

133132
out := stdErr.String()
134133
fmt.Println(out)
135-
assert.True(t, strings.Contains(out, "body size: 21"))
136-
assert.True(t, strings.Contains(out, `initial request body: { "example": "body" }`))
137-
assert.True(t, strings.Contains(out, "on http request body finished"))
138-
assert.False(t, strings.Contains(out, "failed to set request body"))
139-
assert.False(t, strings.Contains(out, "failed to get request body"))
134+
assert.Contains(t, out, "body size: 21")
135+
assert.Contains(t, out, `initial request body: { "example": "body" }`)
136+
assert.Contains(t, out, "on http request body finished")
137+
assert.NotContains(t, out, "failed to set request body")
138+
assert.NotContains(t, out, "failed to get request body")
139+
140+
body, err := ioutil.ReadAll(r.Body)
141+
require.NoError(t, err)
142+
assert.Contains(t, string(body), `"another": "body"`)
140143
}
141144

142145
func TestE2E_network(t *testing.T) {
@@ -166,14 +169,14 @@ func TestE2E_network(t *testing.T) {
166169

167170
out := stdErr.String()
168171
fmt.Println(out)
169-
assert.True(t, strings.Contains(out, key))
170-
assert.True(t, strings.Contains(out, value))
171-
assert.True(t, strings.Contains(out, "downstream data received"))
172-
assert.True(t, strings.Contains(out, "new connection!"))
173-
assert.True(t, strings.Contains(out, "downstream connection close!"))
174-
assert.True(t, strings.Contains(out, "upstream data received"))
175-
assert.True(t, strings.Contains(out, "connection complete!"))
176-
assert.True(t, strings.Contains(out, "remote address: 127.0.0.1:8099"))
172+
assert.Contains(t, out, key)
173+
assert.Contains(t, out, value)
174+
assert.Contains(t, out, "downstream data received")
175+
assert.Contains(t, out, "new connection!")
176+
assert.Contains(t, out, "downstream connection close!")
177+
assert.Contains(t, out, "upstream data received")
178+
assert.Contains(t, out, "connection complete!")
179+
assert.Contains(t, out, "remote address: 127.0.0.1:8099")
177180
}
178181

179182
func TestE2E_metrics(t *testing.T) {
@@ -203,7 +206,7 @@ func TestE2E_metrics(t *testing.T) {
203206

204207
b, err := ioutil.ReadAll(r.Body)
205208
require.NoError(t, err)
206-
assert.True(t, strings.Contains(string(b), fmt.Sprintf("proxy_wasm_go.request_counter: %d", count)))
209+
assert.Contains(t, string(b), fmt.Sprintf("proxy_wasm_go.request_counter: %d", count))
207210
}
208211

209212
func TestE2E_shared_data(t *testing.T) {
@@ -224,7 +227,7 @@ func TestE2E_shared_data(t *testing.T) {
224227

225228
out := stdErr.String()
226229
fmt.Println(out)
227-
assert.True(t, strings.Contains(out, fmt.Sprintf("shared value: %d", count)))
230+
assert.Contains(t, out, fmt.Sprintf("shared value: %d", count))
228231
}
229232

230233
func TestE2E_shared_queue(t *testing.T) {
@@ -247,9 +250,9 @@ func TestE2E_shared_queue(t *testing.T) {
247250

248251
out := stdErr.String()
249252
fmt.Println(out)
250-
assert.True(t, strings.Contains(out, "dequeued data: hello"))
251-
assert.True(t, strings.Contains(out, "dequeued data: world"))
252-
assert.True(t, strings.Contains(out, "dequeued data: proxy-wasm"))
253+
assert.Contains(t, out, "dequeued data: hello")
254+
assert.Contains(t, out, "dequeued data: world")
255+
assert.Contains(t, out, "dequeued data: proxy-wasm")
253256
}
254257

255258
func TestE2E_vm_plugin_configuration(t *testing.T) {
@@ -260,6 +263,6 @@ func TestE2E_vm_plugin_configuration(t *testing.T) {
260263

261264
out := stdErr.String()
262265
fmt.Println(out)
263-
assert.True(t, strings.Contains(out, "name\": \"vm configuration"))
264-
assert.True(t, strings.Contains(out, "name\": \"plugin configuration"))
266+
assert.Contains(t, out, "name\": \"vm configuration")
267+
assert.Contains(t, out, "name\": \"plugin configuration")
265268
}

examples/http_body/envoy.yaml

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static_resources:
2121
- match:
2222
prefix: "/"
2323
route:
24-
cluster: web_service
24+
cluster: httpbin
2525
http_filters:
2626
- name: envoy.filters.http.wasm
2727
config:
@@ -37,43 +37,22 @@ static_resources:
3737
allow_precompiled: true
3838
- name: envoy.router
3939
config: {}
40-
- name: staticreply
41-
address:
42-
socket_address:
43-
address: 127.0.0.1
44-
port_value: 8099
45-
filter_chains:
46-
- filters:
47-
- name: envoy.http_connection_manager
48-
config:
49-
stat_prefix: ingress_http
50-
codec_type: auto
51-
route_config:
52-
name: local_route
53-
virtual_hosts:
54-
- name: local_service
55-
domains:
56-
- "*"
57-
routes:
58-
- match:
59-
prefix: "/"
60-
direct_response:
61-
status: 200
62-
body:
63-
inline_string: "example body\n"
64-
http_filters:
65-
- name: envoy.router
66-
config: {}
6740

6841
clusters:
69-
- name: web_service
70-
connect_timeout: 0.25s
71-
type: static
42+
- name: httpbin
43+
connect_timeout: 1000s
44+
type: strict_dns
7245
lb_policy: round_robin
73-
hosts:
74-
- socket_address:
75-
address: 127.0.0.1
76-
port_value: 8099
46+
load_assignment:
47+
cluster_name: httpbin
48+
endpoints:
49+
- lb_endpoints:
50+
- endpoint:
51+
address:
52+
socket_address:
53+
address: httpbin.org
54+
port_value: 80
55+
7756
admin:
7857
access_log_path: "/dev/null"
7958
address:

0 commit comments

Comments
 (0)