Skip to content

Commit 9e09fbd

Browse files
committed
Refactor test and fix docstring
1 parent d052e83 commit 9e09fbd

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

Diff for: internal/mode/static/nginx/config/base_http_config_test.go

+25-21
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,43 @@ import (
1010
)
1111

1212
func TestExecuteBaseHttp(t *testing.T) {
13-
conf := dataplane.Configuration{
13+
confOn := dataplane.Configuration{
1414
BaseHTTPConfig: dataplane.BaseHTTPConfig{
1515
HTTP2: true,
1616
},
1717
}
1818

19-
g := NewWithT(t)
20-
expSubStrings := map[string]int{
21-
"http2 on;": 1,
22-
}
23-
24-
for expSubStr, expCount := range expSubStrings {
25-
res := executeBaseHTTPConfig(conf)
26-
g.Expect(res).To(HaveLen(1))
27-
g.Expect(expCount).To(Equal(strings.Count(string(res[0].data), expSubStr)))
28-
}
29-
}
30-
31-
func TestExecuteBaseHttpEmpty(t *testing.T) {
32-
conf := dataplane.Configuration{
19+
confOff := dataplane.Configuration{
3320
BaseHTTPConfig: dataplane.BaseHTTPConfig{
3421
HTTP2: false,
3522
},
3623
}
3724

38-
g := NewWithT(t)
39-
expSubStrings := map[string]int{
40-
"http2 on;": 0,
25+
expSubStr := "http2 on;"
26+
27+
tests := []struct {
28+
name string
29+
conf dataplane.Configuration
30+
expCount int
31+
}{
32+
{
33+
name: "http2 on",
34+
conf: confOn,
35+
expCount: 1,
36+
},
37+
{
38+
name: "http2 off",
39+
expCount: 0,
40+
conf: confOff,
41+
},
4142
}
4243

43-
for expSubStr, expCount := range expSubStrings {
44-
res := executeBaseHTTPConfig(conf)
44+
for _, test := range tests {
45+
46+
g := NewWithT(t)
47+
48+
res := executeBaseHTTPConfig(test.conf)
4549
g.Expect(res).To(HaveLen(1))
46-
g.Expect(expCount).To(Equal(strings.Count(string(res[0].data), expSubStr)))
50+
g.Expect(test.expCount).To(Equal(strings.Count(string(res[0].data), expSubStr)))
4751
}
4852
}

Diff for: internal/mode/static/state/dataplane/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,6 @@ type SpanAttribute struct {
284284

285285
// BaseHTTPConfig holds the configuration options at the http context.
286286
type BaseHTTPConfig struct {
287-
// HTTP2 specifies whether http2 should be enabled or disabled for all servers.
287+
// HTTP2 specifies whether http2 should be enabled for all servers.
288288
HTTP2 bool
289289
}

0 commit comments

Comments
 (0)