Skip to content

Commit 2e08001

Browse files
committed
TEST: add checking maps over runtime
Check maps over runtime is done only with go build tag test_todo and executed in a job allowed to fails. Without the tag, with check only the map file content.
1 parent f25604c commit 2e08001

69 files changed

Lines changed: 368 additions & 2016 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.aspell.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ allowed:
7373
- tcp
7474
- tls
7575
- tlsv
76+
- todo
7677
- ubuntu
7778
- unix
7879
- usr

.gitlab/unit-tests.yml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,3 @@ unit-tests-todo:
9191
- junit-report.xml
9292
reports:
9393
junit: junit-report.xml
94-
95-
unit-tests-todo_nowait:
96-
allow_failure: true
97-
needs: ["diff", "tidy"]
98-
rules:
99-
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
100-
- if: "$CI_PROJECT_NAMESPACE != 'haproxy-controller/community' && $CI_PIPELINE_SOURCE == 'push'"
101-
stage: unit-tests
102-
image:
103-
name: $CI_REGISTRY_GO/haproxy-alpine:3.2-go$GO_VERSION
104-
entrypoint: [""]
105-
tags:
106-
- go
107-
before_script:
108-
- export PATH=$PATH:/root/go/bin
109-
script:
110-
- task test-todo_nowait
111-
artifacts:
112-
when: always
113-
paths:
114-
- junit-report.xml
115-
reports:
116-
junit: junit-report.xml

cmd/generate-gwapi/main.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -320,29 +320,6 @@ unit-tests-todo:
320320
- junit-report.xml
321321
reports:
322322
junit: junit-report.xml
323-
324-
unit-tests-todo_nowait:
325-
allow_failure: true
326-
needs: ["diff", "tidy"]
327-
rules:
328-
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
329-
- if: "$CI_PROJECT_NAMESPACE != 'haproxy-controller/community' && $CI_PIPELINE_SOURCE == 'push'"
330-
stage: unit-tests
331-
image:
332-
name: $CI_REGISTRY_GO/haproxy-alpine:3.2-go$GO_VERSION
333-
entrypoint: [""]
334-
tags:
335-
- go
336-
before_script:
337-
- export PATH=$PATH:/root/go/bin
338-
script:
339-
- task test-todo_nowait
340-
artifacts:
341-
when: always
342-
paths:
343-
- junit-report.xml
344-
reports:
345-
junit: junit-report.xml
346323
`
347324

348325
var conditionsKOTmpl = `# Code generated by cmd/generate-gwapi; DO NOT EDIT.

taskfile.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ tasks:
5454
vars:
5555
TEST_TAGS: "test_todo"
5656

57-
test-todo_nowait:
58-
desc: "run Go tests"
59-
cmds:
60-
- task: test
61-
vars:
62-
TEST_TAGS: "test_todo_nowait"
63-
6457
test:
6558
desc: "run Go tests"
6659
deps:

test/integration/base/base.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (b *BaseSuite) CreateFixtures(fixturePath string, manifestNames []string) {
9292
// Note that CleanupFixturesCheckMapFiles will wait until the map file is empty before
9393
// returning. This is to ensure that the test does not finish before the cleanup
9494
// has finished.
95-
func (b *BaseSuite) CleanupFixturesCheckMapFiles(fixturePath string, manifestNames []string, mapFileRelativePath string) {
95+
func (b *BaseSuite) CleanupFixturesCheckMapFiles(fixturePath string, manifestNames []string, mapFileRelativePaths []string) {
9696
b.T().Logf("Cleaning up fixtures in %s", fixturePath)
9797
defer b.T().Logf("End of cleaning up fixtures in %s", fixturePath)
9898
params := utils.RuntimeYamlParams{
@@ -105,13 +105,9 @@ func (b *BaseSuite) CleanupFixturesCheckMapFiles(fixturePath string, manifestNam
105105
}
106106
err := utils.DeleteRuntimeObjectsFromYAMLFiles(params)
107107
b.Require().NoError(err)
108-
b.Eventually(func() bool {
109-
emptyMapFile := b.CheckMapContents(mapFileRelativePath, "")
110-
if !emptyMapFile {
111-
return false
112-
}
113-
return b.CheckRuntimeMapContents(mapFileRelativePath, "")
114-
}, timeout, interval, fmt.Sprintf("maps in %s were not emptied", mapFileRelativePath))
108+
for _, mapFileRelativePath := range mapFileRelativePaths {
109+
b.ExpectMapContents(mapFileRelativePath, "")
110+
}
115111
}
116112

117113
func (b *BaseSuite) CreateFixturesInNamespace(fixturePath, namespace string, manifestNames []string) {
@@ -414,19 +410,25 @@ var StandardMaps = []string{
414410
}
415411

416412
func (b *BaseSuite) ExpectMapContents(mapFilePath, expectedMapPath string) {
417-
res := b.Eventually(func() bool {
413+
b.Require().Eventually(func() bool {
418414
check := b.CheckMapContents(mapFilePath, expectedMapPath)
419415
return check
420416
}, timeout, interval, fmt.Sprintf("maps in %s did not match expected contents", mapFilePath))
421-
if !res {
422-
msg := fmt.Sprintf("maps in %s did not match expected contents", mapFilePath)
423-
b.T().Fatal(msg)
424-
}
425417
}
426418

427419
func (b *BaseSuite) CheckMapContents(mapFileRelativePath, expectedMapPath string) bool {
428-
b.T().Logf("Checking map contents in %s", mapFileRelativePath)
429-
b.T().Logf("with expected map path %s", expectedMapPath)
420+
checkFile := b.CheckMapFileContents(mapFileRelativePath, expectedMapPath)
421+
if !checkFile {
422+
return false
423+
}
424+
if TestMapThroughRuntime {
425+
return b.CheckRuntimeMapContents(mapFileRelativePath, expectedMapPath)
426+
}
427+
return true
428+
}
429+
430+
func (b *BaseSuite) CheckMapFileContents(mapFileRelativePath, expectedMapPath string) bool {
431+
b.T().Logf("Checking map [file] in %s with expected map path %s", mapFileRelativePath, expectedMapPath)
430432
for _, mapName := range StandardMaps {
431433
expectedFilePath := path.Join(expectedMapPath, mapName)
432434

@@ -446,18 +448,18 @@ func (b *BaseSuite) CheckMapContents(mapFileRelativePath, expectedMapPath string
446448
if expectationExists {
447449
// Check if content matches
448450
if string(expectedContent) != actualString {
449-
b.T().Logf("Map mismatch for %s: \nexpected %q, \ngot %q", mapName, string(expectedContent), actualString)
451+
b.T().Logf(" map [file] mismatch for %s: \nexpected %q, \ngot %q", mapName, string(expectedContent), actualString)
450452
return false
451453
}
452454
} else {
453455
// Check if actual is empty
454456
if strings.TrimSpace(actualString) != "" {
455-
b.T().Logf("Map %s should be empty but has content: %q", mapName, actualString)
457+
b.T().Logf(" map [file] %s should be empty but has content: %q", mapName, actualString)
456458
return false
457459
}
458460
}
459461
}
460-
b.T().Logf("Map contents correct for %s", mapFileRelativePath)
462+
b.T().Logf(" map [file] correct for %s", mapFileRelativePath)
461463
return true
462464
}
463465

@@ -636,8 +638,7 @@ func (b *BaseSuite) ConsistentlyNoReload(oldPid string, duration time.Duration)
636638
}
637639

638640
func (b *BaseSuite) CheckRuntimeMapContents(mapFileRelativePath, expectedMapPath string) bool {
639-
b.T().Logf("Checking runtime map contents for %s with expected map path %s", mapFileRelativePath, expectedMapPath)
640-
defer b.T().Logf("End of checking runtime map contents for %s with expected map path %s", mapFileRelativePath, expectedMapPath)
641+
b.T().Logf("Checking map [runtime] for %s with expected map path %s", mapFileRelativePath, expectedMapPath)
641642
socketPath := filepath.Join(b.test.HaproxyCfgDir, "haproxy-runtime-api.sock")
642643

643644
for _, mapName := range StandardMaps {
@@ -669,11 +670,11 @@ func (b *BaseSuite) CheckRuntimeMapContents(mapFileRelativePath, expectedMapPath
669670
}
670671

671672
if expectationExists {
672-
b.T().Logf("Runtime map contents: %s", actualNormalized)
673-
b.T().Logf("Expected runtime map contents: %s", expectedNormalized)
673+
b.T().Logf("map [runtime] contents: %s", actualNormalized)
674+
b.T().Logf("Expected map [runtime] contents: %s", expectedNormalized)
674675
if expectedNormalized != actualNormalized {
675676
b.T().Logf(
676-
"Runtime map mismatch for %s:\nexpected:\n%q\ngot:\n%q",
677+
" map [runtime] mismatch for %s:\nexpected:\n%q\ngot:\n%q",
677678
mapName,
678679
expectedNormalized,
679680
actualNormalized,
@@ -683,14 +684,15 @@ func (b *BaseSuite) CheckRuntimeMapContents(mapFileRelativePath, expectedMapPath
683684
} else {
684685
if strings.TrimSpace(actualNormalized) != "" {
685686
b.T().Logf(
686-
"Runtime map %s should be empty but has content: %q",
687+
" map [runtime] %s should be empty but has content: %q",
687688
mapName,
688689
actualNormalized,
689690
)
690691
return false
691692
}
692693
}
693694
}
695+
b.T().Logf(" map [runtime] correct for %s", mapFileRelativePath)
694696

695697
return true
696698
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build !test_todo
2+
3+
// Copyright 2019 HAProxy Technologies LLC
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package base
18+
19+
const (
20+
TestMapThroughRuntime = false
21+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build test_todo
2+
3+
// Copyright 2019 HAProxy Technologies LLC
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package base
18+
19+
const (
20+
TestMapThroughRuntime = true
21+
)

test/integration/hostnames-matchtype/1-gw-exact-route-exact-match-exact/hostnames_matchtype_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package hostnames_matchtype1
1616

1717
import (
18-
"fmt"
1918
"path"
2019

2120
"github.com/haproxytech/haproxy-unified-gateway/test/integration/utils"
@@ -27,7 +26,9 @@ func (s *HostnamesMatchtypeSuite1) Test_1_Exact_Route_Exact_Match_Exact() {
2726

2827
fixturePath := path.Join(fixtureDirPath, fixtureDir)
2928
s.CreateFixtures(fixturePath, nil)
30-
defer s.CleanupFixtures(fixturePath, nil)
29+
mapFilePath1 := "hug_http_31081"
30+
mapFilePath2 := "hug_https_31444"
31+
defer s.CleanupFixturesCheckMapFiles(fixturePath, nil, []string{mapFilePath1, mapFilePath2})
3132

3233
// Expected Conditions
3334
expectationsPath := path.Join(fixturePath, "expectations")
@@ -45,14 +46,8 @@ func (s *HostnamesMatchtypeSuite1) Test_1_Exact_Route_Exact_Match_Exact() {
4546
expectedMapsPath := path.Join("expectations", "maps")
4647

4748
// For FE http
48-
mapFilePath := "hug_http_31081"
49-
s.Eventually(func() bool {
50-
return s.CheckMapContents(mapFilePath, expectedMapsPath)
51-
}, timeout, interval, fmt.Sprintf("maps in %s did not match expected contents", mapFilePath))
49+
s.ExpectMapContents(mapFilePath1, expectedMapsPath)
5250

5351
// For FE https
54-
mapFilePath = "hug_https_31444"
55-
s.Eventually(func() bool {
56-
return s.CheckMapContents(mapFilePath, expectedMapsPath)
57-
}, timeout, interval, fmt.Sprintf("maps in %s did not match expected contents", mapFilePath))
52+
s.ExpectMapContents(mapFilePath2, expectedMapsPath)
5853
}

test/integration/hostnames-matchtype/1-gw-exact-route-exact-match-exact/suite_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@ package hostnames_matchtype1
1616

1717
import (
1818
"testing"
19-
"time"
2019

2120
"github.com/haproxytech/haproxy-unified-gateway/test/integration/base"
2221

2322
"github.com/stretchr/testify/suite"
2423
)
2524

26-
const (
27-
timeout = time.Second * 30
28-
interval = time.Second * 1
29-
)
30-
3125
type HostnamesMatchtypeSuite1 struct {
3226
base.BaseSuite
3327
}

test/integration/hostnames-matchtype/10-gw-exact-route-empty-match-prefix/hostnames_matchtype_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package hostnames_matchtype10
1616

1717
import (
18-
"fmt"
1918
"path"
2019

2120
"github.com/haproxytech/haproxy-unified-gateway/test/integration/utils"
@@ -27,7 +26,9 @@ func (s *HostnamesMatchtypeSuite10) Test_10_Exact_Route_Empty_Match_Prefix() {
2726

2827
fixturePath := path.Join(fixtureDirPath, fixtureDir)
2928
s.CreateFixtures(fixturePath, nil)
30-
defer s.CleanupFixtures(fixturePath, nil)
29+
mapFilePath1 := "hug_http_31081"
30+
mapFilePath2 := "hug_https_31444"
31+
defer s.CleanupFixturesCheckMapFiles(fixturePath, nil, []string{mapFilePath1, mapFilePath2})
3132

3233
// Expected Conditions
3334
expectationsPath := path.Join(fixturePath, "expectations")
@@ -45,14 +46,8 @@ func (s *HostnamesMatchtypeSuite10) Test_10_Exact_Route_Empty_Match_Prefix() {
4546
expectedMapsPath := path.Join("expectations", "maps")
4647

4748
// For FE http
48-
mapFilePath := "hug_http_31081"
49-
s.Eventually(func() bool {
50-
return s.CheckMapContents(mapFilePath, expectedMapsPath)
51-
}, timeout, interval, fmt.Sprintf("maps in %s did not match expected contents", mapFilePath))
49+
s.ExpectMapContents(mapFilePath1, expectedMapsPath)
5250

5351
// For FE https
54-
mapFilePath = "hug_https_31444"
55-
s.Eventually(func() bool {
56-
return s.CheckMapContents(mapFilePath, expectedMapsPath)
57-
}, timeout, interval, fmt.Sprintf("maps in %s did not match expected contents", mapFilePath))
52+
s.ExpectMapContents(mapFilePath2, expectedMapsPath)
5853
}

0 commit comments

Comments
 (0)