Skip to content

Commit

Permalink
Run tests in internal/mode/static/nginx/config in parallel (2) (#2533)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome authored Sep 11, 2024
1 parent 8fb93bb commit e324a64
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 13 deletions.
20 changes: 12 additions & 8 deletions internal/mode/static/nginx/config/base_http_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func TestExecuteBaseHttp(t *testing.T) {
t.Parallel()
confOn := dataplane.Configuration{
BaseHTTPConfig: dataplane.BaseHTTPConfig{
HTTP2: true,
Expand Down Expand Up @@ -42,13 +43,16 @@ func TestExecuteBaseHttp(t *testing.T) {
}

for _, test := range tests {
g := NewWithT(t)

res := executeBaseHTTPConfig(test.conf)
g.Expect(res).To(HaveLen(1))
g.Expect(test.expCount).To(Equal(strings.Count(string(res[0].data), expSubStr)))
g.Expect(strings.Count(string(res[0].data), "map $http_host $gw_api_compliant_host {")).To(Equal(1))
g.Expect(strings.Count(string(res[0].data), "map $http_upgrade $connection_upgrade {")).To(Equal(1))
g.Expect(strings.Count(string(res[0].data), "map $request_uri $request_uri_path {")).To(Equal(1))
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

res := executeBaseHTTPConfig(test.conf)
g.Expect(res).To(HaveLen(1))
g.Expect(test.expCount).To(Equal(strings.Count(string(res[0].data), expSubStr)))
g.Expect(strings.Count(string(res[0].data), "map $http_host $gw_api_compliant_host {")).To(Equal(1))
g.Expect(strings.Count(string(res[0].data), "map $http_upgrade $connection_upgrade {")).To(Equal(1))
g.Expect(strings.Count(string(res[0].data), "map $request_uri $request_uri_path {")).To(Equal(1))
})
}
}
1 change: 1 addition & 0 deletions internal/mode/static/nginx/config/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func TestConvertEndpoints(t *testing.T) {
t.Parallel()
endpoints := []resolver.Endpoint{
{
Address: "1.2.3.4",
Expand Down
1 change: 1 addition & 0 deletions internal/mode/static/nginx/config/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

func TestGenerate(t *testing.T) {
t.Parallel()
bg := dataplane.BackendGroup{
Source: types.NamespacedName{Namespace: "test", Name: "hr"},
RuleIdx: 0,
Expand Down
5 changes: 5 additions & 0 deletions internal/mode/static/nginx/config/maps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

func TestExecuteMaps(t *testing.T) {
t.Parallel()
g := NewWithT(t)
pathRules := []dataplane.PathRule{
{
Expand Down Expand Up @@ -97,6 +98,7 @@ func TestExecuteMaps(t *testing.T) {
}

func TestBuildAddHeaderMaps(t *testing.T) {
t.Parallel()
g := NewWithT(t)
pathRules := []dataplane.PathRule{
{
Expand Down Expand Up @@ -190,6 +192,7 @@ func TestBuildAddHeaderMaps(t *testing.T) {
}

func TestExecuteStreamMaps(t *testing.T) {
t.Parallel()
g := NewWithT(t)
conf := dataplane.Configuration{
TLSPassthroughServers: []dataplane.Layer4VirtualServer{
Expand Down Expand Up @@ -257,6 +260,7 @@ func TestExecuteStreamMaps(t *testing.T) {
}

func TestCreateStreamMaps(t *testing.T) {
t.Parallel()
g := NewWithT(t)
conf := dataplane.Configuration{
TLSPassthroughServers: []dataplane.Layer4VirtualServer{
Expand Down Expand Up @@ -371,6 +375,7 @@ func TestCreateStreamMaps(t *testing.T) {
}

func TestCreateStreamMapsWithEmpty(t *testing.T) {
t.Parallel()
g := NewWithT(t)
conf := dataplane.Configuration{
TLSPassthroughServers: nil,
Expand Down
51 changes: 46 additions & 5 deletions internal/mode/static/nginx/config/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
)

func TestExecuteServers(t *testing.T) {
t.Parallel()
conf := dataplane.Configuration{
HTTPServers: []dataplane.VirtualServer{
{
Expand Down Expand Up @@ -145,6 +146,7 @@ func TestExecuteServers(t *testing.T) {
}

func TestExecuteServers_IPFamily(t *testing.T) {
t.Parallel()
httpServers := []dataplane.VirtualServer{
{
IsDefault: true,
Expand Down Expand Up @@ -267,6 +269,7 @@ func TestExecuteServers_IPFamily(t *testing.T) {

for _, test := range tests {
t.Run(test.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

gen := GeneratorImpl{}
Expand All @@ -284,6 +287,7 @@ func TestExecuteServers_IPFamily(t *testing.T) {
}

func TestExecuteServers_RewriteClientIP(t *testing.T) {
t.Parallel()
httpServers := []dataplane.VirtualServer{
{
IsDefault: true,
Expand Down Expand Up @@ -383,6 +387,7 @@ func TestExecuteServers_RewriteClientIP(t *testing.T) {

for _, test := range tests {
t.Run(test.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

gen := GeneratorImpl{}
Expand All @@ -400,6 +405,7 @@ func TestExecuteServers_RewriteClientIP(t *testing.T) {
}

func TestExecuteServers_Plus(t *testing.T) {
t.Parallel()
config := dataplane.Configuration{
HTTPServers: []dataplane.VirtualServer{
{
Expand Down Expand Up @@ -438,6 +444,7 @@ func TestExecuteServers_Plus(t *testing.T) {
}

func TestExecuteForDefaultServers(t *testing.T) {
t.Parallel()
testcases := []struct {
msg string
httpPorts []int
Expand Down Expand Up @@ -506,6 +513,7 @@ func TestExecuteForDefaultServers(t *testing.T) {

for _, tc := range testcases {
t.Run(tc.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

gen := GeneratorImpl{}
Expand All @@ -527,6 +535,7 @@ func TestExecuteForDefaultServers(t *testing.T) {
}

func TestCreateServers(t *testing.T) {
t.Parallel()
const (
sslKeyPairID = "test-keypair"
)
Expand Down Expand Up @@ -1498,6 +1507,7 @@ func modifyMatchPairs(matchPairs httpMatchPairs) httpMatchPairs {
}

func TestCreateServersConflicts(t *testing.T) {
t.Parallel()
fooGroup := dataplane.BackendGroup{
Source: types.NamespacedName{Namespace: "test", Name: "route"},
RuleIdx: 0,
Expand Down Expand Up @@ -1671,6 +1681,7 @@ func TestCreateServersConflicts(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
httpServers := []dataplane.VirtualServer{
{
IsDefault: true,
Expand Down Expand Up @@ -1703,6 +1714,7 @@ func TestCreateServersConflicts(t *testing.T) {
}

func TestCreateLocationsRootPath(t *testing.T) {
t.Parallel()
hrNsName := types.NamespacedName{Namespace: "test", Name: "route1"}

fooGroup := dataplane.BackendGroup{
Expand Down Expand Up @@ -1869,6 +1881,7 @@ func TestCreateLocationsRootPath(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

locs, httpMatchPair, grpc := createLocations(&dataplane.VirtualServer{
Expand All @@ -1883,6 +1896,7 @@ func TestCreateLocationsRootPath(t *testing.T) {
}

func TestCreateReturnValForRedirectFilter(t *testing.T) {
t.Parallel()
const listenerPortCustom = 123
const listenerPortHTTP = 80
const listenerPortHTTPS = 443
Expand Down Expand Up @@ -2005,6 +2019,7 @@ func TestCreateReturnValForRedirectFilter(t *testing.T) {

for _, test := range tests {
t.Run(test.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

result := createReturnValForRedirectFilter(test.filter, test.listenerPort)
Expand All @@ -2014,6 +2029,7 @@ func TestCreateReturnValForRedirectFilter(t *testing.T) {
}

func TestCreateRewritesValForRewriteFilter(t *testing.T) {
t.Parallel()
tests := []struct {
filter *dataplane.HTTPURLRewriteFilter
expected *rewriteConfig
Expand Down Expand Up @@ -2131,6 +2147,7 @@ func TestCreateRewritesValForRewriteFilter(t *testing.T) {

for _, test := range tests {
t.Run(test.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

result := createRewritesValForRewriteFilter(test.filter, test.path)
Expand All @@ -2140,6 +2157,7 @@ func TestCreateRewritesValForRewriteFilter(t *testing.T) {
}

func TestCreateRouteMatch(t *testing.T) {
t.Parallel()
testPath := "/internal_loc"

testMethodMatch := helpers.GetPointer("PUT")
Expand Down Expand Up @@ -2290,6 +2308,7 @@ func TestCreateRouteMatch(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

result := createRouteMatch(tc.match, testPath)
Expand All @@ -2299,6 +2318,7 @@ func TestCreateRouteMatch(t *testing.T) {
}

func TestCreateQueryParamKeyValString(t *testing.T) {
t.Parallel()
g := NewWithT(t)

expected := "key=value"
Expand All @@ -2325,6 +2345,7 @@ func TestCreateQueryParamKeyValString(t *testing.T) {
}

func TestCreateHeaderKeyValString(t *testing.T) {
t.Parallel()
g := NewWithT(t)

expected := "kEy:vALUe"
Expand All @@ -2340,6 +2361,7 @@ func TestCreateHeaderKeyValString(t *testing.T) {
}

func TestIsPathOnlyMatch(t *testing.T) {
t.Parallel()
tests := []struct {
msg string
match dataplane.Match
Expand Down Expand Up @@ -2385,6 +2407,7 @@ func TestIsPathOnlyMatch(t *testing.T) {

for _, tc := range tests {
t.Run(tc.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

result := isPathOnlyMatch(tc.match)
Expand All @@ -2394,7 +2417,7 @@ func TestIsPathOnlyMatch(t *testing.T) {
}

func TestCreateProxyPass(t *testing.T) {
g := NewWithT(t)
t.Parallel()

tests := []struct {
rewrite *dataplane.HTTPURLRewriteFilter
Expand Down Expand Up @@ -2463,12 +2486,17 @@ func TestCreateProxyPass(t *testing.T) {
}

for _, tc := range tests {
result := createProxyPass(tc.grp, tc.rewrite, generateProtocolString(nil, tc.GRPC), tc.GRPC)
g.Expect(result).To(Equal(tc.expected))
t.Run(tc.expected, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
result := createProxyPass(tc.grp, tc.rewrite, generateProtocolString(nil, tc.GRPC), tc.GRPC)
g.Expect(result).To(Equal(tc.expected))
})
}
}

func TestCreateMatchLocation(t *testing.T) {
t.Parallel()
g := NewWithT(t)

expectedNoGRPC := http.Location{
Expand All @@ -2492,6 +2520,7 @@ func TestCreateMatchLocation(t *testing.T) {
}

func TestGenerateProxySetHeaders(t *testing.T) {
t.Parallel()
tests := []struct {
filters *dataplane.HTTPFilters
msg string
Expand Down Expand Up @@ -2685,6 +2714,7 @@ func TestGenerateProxySetHeaders(t *testing.T) {

for _, tc := range tests {
t.Run(tc.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

headers := generateProxySetHeaders(tc.filters, tc.GRPC)
Expand All @@ -2694,7 +2724,7 @@ func TestGenerateProxySetHeaders(t *testing.T) {
}

func TestConvertBackendTLSFromGroup(t *testing.T) {
g := NewWithT(t)
t.Parallel()

tests := []struct {
expected *http.ProxySSLVerify
Expand Down Expand Up @@ -2775,14 +2805,18 @@ func TestConvertBackendTLSFromGroup(t *testing.T) {
}

for _, tc := range tests {
t.Run(tc.msg, func(_ *testing.T) {
t.Run(tc.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

result := createProxyTLSFromBackends(tc.grp)
g.Expect(result).To(Equal(tc.expected))
})
}
}

func TestGenerateResponseHeaders(t *testing.T) {
t.Parallel()
tests := []struct {
filters *dataplane.HTTPFilters
msg string
Expand Down Expand Up @@ -2842,6 +2876,7 @@ func TestGenerateResponseHeaders(t *testing.T) {

for _, tc := range tests {
t.Run(tc.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

headers := generateResponseHeaders(tc.filters)
Expand All @@ -2851,6 +2886,7 @@ func TestGenerateResponseHeaders(t *testing.T) {
}

func TestCreateIncludesFromPolicyGenerateResult(t *testing.T) {
t.Parallel()
tests := []struct {
name string
files []policies.File
Expand Down Expand Up @@ -2896,6 +2932,7 @@ func TestCreateIncludesFromPolicyGenerateResult(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

includes := createIncludesFromPolicyGenerateResult(test.files)
Expand All @@ -2905,6 +2942,7 @@ func TestCreateIncludesFromPolicyGenerateResult(t *testing.T) {
}

func TestCreateIncludeFileResults(t *testing.T) {
t.Parallel()
servers := []http.Server{
{
Includes: []http.Include{
Expand Down Expand Up @@ -2995,6 +3033,7 @@ func TestCreateIncludeFileResults(t *testing.T) {
}

func TestGetIPFamily(t *testing.T) {
t.Parallel()
test := []struct {
msg string
baseHTTPConfig dataplane.BaseHTTPConfig
Expand All @@ -3019,7 +3058,9 @@ func TestGetIPFamily(t *testing.T) {

for _, tc := range test {
t.Run(tc.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

result := getIPFamily(tc.baseHTTPConfig)
g.Expect(result).To(Equal(tc.expected))
})
Expand Down
Loading

0 comments on commit e324a64

Please sign in to comment.