Skip to content

Commit

Permalink
Refactor test and fix docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
ciarams87 committed May 16, 2024
1 parent 6ba60f6 commit 1e02137
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
46 changes: 25 additions & 21 deletions internal/mode/static/nginx/config/base_http_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,43 @@ import (
)

func TestExecuteBaseHttp(t *testing.T) {
conf := dataplane.Configuration{
confOn := dataplane.Configuration{
BaseHTTPConfig: dataplane.BaseHTTPConfig{
HTTP2: true,
},
}

g := NewWithT(t)
expSubStrings := map[string]int{
"http2 on;": 1,
}

for expSubStr, expCount := range expSubStrings {
res := executeBaseHTTPConfig(conf)
g.Expect(res).To(HaveLen(1))
g.Expect(expCount).To(Equal(strings.Count(string(res[0].data), expSubStr)))
}
}

func TestExecuteBaseHttpEmpty(t *testing.T) {
conf := dataplane.Configuration{
confOff := dataplane.Configuration{
BaseHTTPConfig: dataplane.BaseHTTPConfig{
HTTP2: false,
},
}

g := NewWithT(t)
expSubStrings := map[string]int{
"http2 on;": 0,
expSubStr := "http2 on;"

tests := []struct {
name string
conf dataplane.Configuration
expCount int
}{
{
name: "http2 on",
conf: confOn,
expCount: 1,
},
{
name: "http2 off",
expCount: 0,
conf: confOff,
},
}

for expSubStr, expCount := range expSubStrings {
res := executeBaseHTTPConfig(conf)
for _, test := range tests {

g := NewWithT(t)

res := executeBaseHTTPConfig(test.conf)
g.Expect(res).To(HaveLen(1))
g.Expect(expCount).To(Equal(strings.Count(string(res[0].data), expSubStr)))
g.Expect(test.expCount).To(Equal(strings.Count(string(res[0].data), expSubStr)))
}
}
2 changes: 1 addition & 1 deletion internal/mode/static/state/dataplane/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,6 @@ type SpanAttribute struct {

// BaseHTTPConfig holds the configuration options at the http context.
type BaseHTTPConfig struct {
// HTTP2 specifies whether http2 should be enabled or disabled for all servers.
// HTTP2 specifies whether http2 should be enabled for all servers.
HTTP2 bool
}

0 comments on commit 1e02137

Please sign in to comment.