Skip to content

Commit

Permalink
TEST/MINOR: fix usage of testify NoError
Browse files Browse the repository at this point in the history
the way we were using suite.NoError was not stopping the test in case of error. Fixing this.
  • Loading branch information
hdurand0710 committed Oct 18, 2024
1 parent 957d3d3 commit ea3ffa0
Show file tree
Hide file tree
Showing 42 changed files with 137 additions and 137 deletions.
36 changes: 18 additions & 18 deletions deploy/tests/e2e/access-control/access_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (suite *AccessControlSuite) Test_Whitelist() {
{"allow-list", " 192.168.2.0/24"},
}

suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))

suite.eventuallyReturns("192.168.2.3", http.StatusOK)
suite.eventuallyReturns("192.168.5.3", http.StatusForbidden)
Expand All @@ -57,7 +57,7 @@ func (suite *AccessControlSuite) Test_Whitelist() {
{"whitelist", "192.168.4.0/24"},
}

suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))

suite.eventuallyReturns("192.168.4.3", http.StatusOK)
suite.eventuallyReturns("192.168.5.3", http.StatusForbidden)
Expand All @@ -71,7 +71,7 @@ func (suite *AccessControlSuite) Test_Whitelist() {
{"allow-list", "192.168.5.0/24"},
}

suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))

suite.eventuallyReturns("192.168.5.3", http.StatusOK)
suite.eventuallyReturns("192.168.4.3", http.StatusForbidden)
Expand All @@ -84,8 +84,8 @@ func (suite *AccessControlSuite) Test_Whitelist() {
{"allow-list", " patterns/ips"},
}

suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.NoError(suite.test.Apply("config/patternfile-a.yml", "", nil))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/patternfile-a.yml", "", nil))

suite.eventuallyReturns("192.168.0.3", http.StatusOK)
suite.eventuallyReturns("192.168.2.3", http.StatusForbidden)
Expand All @@ -98,8 +98,8 @@ func (suite *AccessControlSuite) Test_Whitelist() {
{"whitelist", " patterns/ips2"},
}

suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.NoError(suite.test.Apply("config/patternfile-a.yml", "", nil))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/patternfile-a.yml", "", nil))

suite.eventuallyReturns("192.169.0.3", http.StatusOK)
suite.eventuallyReturns("192.168.2.3", http.StatusForbidden)
Expand All @@ -113,8 +113,8 @@ func (suite *AccessControlSuite) Test_Whitelist() {
{"allow-list", " patterns/ips"},
}

suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.NoError(suite.test.Apply("config/patternfile-a.yml", "", nil))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/patternfile-a.yml", "", nil))

suite.eventuallyReturns("192.168.0.3", http.StatusOK)
suite.eventuallyReturns("192.168.2.3", http.StatusForbidden)
Expand All @@ -129,7 +129,7 @@ func (suite *AccessControlSuite) Test_Blacklist() {
{"deny-list", " 192.168.2.0/24"},
}

suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))

suite.eventuallyReturns("192.168.2.3", http.StatusForbidden)
suite.eventuallyReturns("192.168.5.3", http.StatusOK)
Expand All @@ -142,7 +142,7 @@ func (suite *AccessControlSuite) Test_Blacklist() {
{"blacklist", "192.168.4.0/24"},
}

suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))

suite.eventuallyReturns("192.168.4.3", http.StatusForbidden)
suite.eventuallyReturns("192.168.5.3", http.StatusOK)
Expand All @@ -156,7 +156,7 @@ func (suite *AccessControlSuite) Test_Blacklist() {
{"deny-list", "192.168.5.0/24"},
}

suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))

suite.eventuallyReturns("192.168.5.3", http.StatusForbidden)
suite.eventuallyReturns("192.168.4.3", http.StatusOK)
Expand All @@ -169,8 +169,8 @@ func (suite *AccessControlSuite) Test_Blacklist() {
{"deny-list", "patterns/ips"},
}

suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.NoError(suite.test.Apply("config/patternfile-a.yml", "", nil))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/patternfile-a.yml", "", nil))

suite.eventuallyReturns("192.168.0.3", http.StatusForbidden)
suite.eventuallyReturns("192.168.2.3", http.StatusOK)
Expand All @@ -183,8 +183,8 @@ func (suite *AccessControlSuite) Test_Blacklist() {
{"blacklist", " patterns/ips2"},
}

suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.NoError(suite.test.Apply("config/patternfile-a.yml", "", nil))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/patternfile-a.yml", "", nil))

suite.eventuallyReturns("192.169.0.3", http.StatusForbidden)
suite.eventuallyReturns("192.168.2.3", http.StatusOK)
Expand All @@ -197,8 +197,8 @@ func (suite *AccessControlSuite) Test_Blacklist() {
{"deny-list", "patterns/ips"},
}

suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.NoError(suite.test.Apply("config/patternfile-a.yml", "", nil))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/patternfile-a.yml", "", nil))

suite.eventuallyReturns("192.168.0.3", http.StatusForbidden)
suite.eventuallyReturns("192.169.2.3", http.StatusOK)
Expand Down
6 changes: 3 additions & 3 deletions deploy/tests/e2e/access-control/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ type tmplData struct {
func (suite *AccessControlSuite) SetupSuite() {
var err error
suite.test, err = e2e.NewTest()
suite.NoError(err)
suite.Require().NoError(err)
suite.tmplData = tmplData{Host: suite.test.GetNS() + ".test"}
suite.client, err = e2e.NewHTTPClient(suite.tmplData.Host)
suite.NoError(err)
suite.Require().NoError(err)

suite.NoError(suite.test.Apply("config/patternfile-empty.yml", "", nil))
suite.Require().NoError(suite.test.Apply("config/patternfile-empty.yml", "", nil))
}

func (suite *AccessControlSuite) TearDownSuite() {
Expand Down
4 changes: 2 additions & 2 deletions deploy/tests/e2e/admin-port/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ type tmplData struct {
func (suite *AdminPortSuite) SetupSuite() {
var err error
suite.test, err = e2e.NewTest()
suite.NoError(err)
suite.Require().NoError(err)
suite.tmplData = tmplData{Host: suite.test.GetNS() + ".test"}
suite.client, err = e2e.NewHTTPClient(suite.tmplData.Host)
suite.NoError(err)
suite.Require().NoError(err)
}

func (suite *AdminPortSuite) TearDownSuite() {
Expand Down
2 changes: 1 addition & 1 deletion deploy/tests/e2e/basic-auth/basic_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

func (suite *HTTPBasicAuthSuite) Test_BasicAuth() {
suite.Run("Denied", func() {
suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().Eventually(func() bool {
res, cls, err := suite.client.Do()
if res == nil {
Expand Down
4 changes: 2 additions & 2 deletions deploy/tests/e2e/basic-auth/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ type tmplData struct {
func (suite *HTTPBasicAuthSuite) SetupSuite() {
var err error
suite.test, err = e2e.NewTest()
suite.NoError(err)
suite.Require().NoError(err)
suite.tmplData = tmplData{Host: suite.test.GetNS() + ".test"}
suite.client, err = e2e.NewHTTPClient(suite.tmplData.Host)
suite.NoError(err)
suite.Require().NoError(err)
}

func (suite *HTTPBasicAuthSuite) TearDownSuite() {
Expand Down
2 changes: 1 addition & 1 deletion deploy/tests/e2e/canary-deployment/percentage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (suite *CanaryDeploymentSuite) Test_Response_Percentage() {
for _, percentage := range []int{0, 25, 100} {
suite.Run(fmt.Sprintf("%d", percentage), func() {
suite.tmplData.StagingRouteACL = fmt.Sprintf("rand(100) lt %d", percentage)
suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Eventually(func() bool {
counter := 0
for i := 0; i < 10; i++ {
Expand Down
4 changes: 2 additions & 2 deletions deploy/tests/e2e/canary-deployment/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ type tmplData struct {
func (suite *CanaryDeploymentSuite) SetupSuite() {
var err error
suite.test, err = e2e.NewTest()
suite.NoError(err)
suite.Require().NoError(err)
suite.tmplData = tmplData{
Host: suite.test.GetNS() + ".test",
StagingRouteACL: "rand(100) lt 0",
}
suite.client, err = e2e.NewHTTPClient(suite.tmplData.Host)
suite.NoError(err)
suite.Require().NoError(err)
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().Eventually(func() bool {
res, cls, err := suite.client.Do()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func (suite *ConfigSnippetSuite) TestBackendCfgSnippet() {
suite.NoError(suite.test.Apply("config/backend-cfg-snippet.yaml", suite.test.GetNS(), nil))
suite.Require().NoError(suite.test.Apply("config/backend-cfg-snippet.yaml", suite.test.GetNS(), nil))
suite.Eventually(func() bool {
res, cls, err := suite.client.Do()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func (suite *ConfigSnippetSuite) TestFrontendCfgSnippet() {
suite.NoError(suite.test.Apply("config/configmap.yaml", "", nil))
suite.Require().NoError(suite.test.Apply("config/configmap.yaml", "", nil))
suite.Eventually(func() bool {
res, cls, err := suite.client.Do()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions deploy/tests/e2e/config-snippet/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ type tmplData struct {
func (suite *ConfigSnippetSuite) SetupSuite() {
var err error
suite.test, err = e2e.NewTest()
suite.NoError(err)
suite.Require().NoError(err)
suite.tmplData = tmplData{Host: suite.test.GetNS() + ".test"}
suite.client, err = e2e.NewHTTPClient(suite.tmplData.Host)
suite.NoError(err)
suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(err)
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().Eventually(func() bool {
res, cls, err := suite.client.Do()
if res == nil {
Expand Down
18 changes: 9 additions & 9 deletions deploy/tests/e2e/cors/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (suite *CorsSuite) Test_Configmap_Alone() {
suite.Run("CorsMethodsCredentialAlone", suite.CorsMethodsCredentialAlone(false))
suite.Run("CorsDisable", suite.CorsDisable(false))
suite.Run("CorsMethodsCredentialDisable", suite.CorsMethodsCredentialDisable(false))
suite.NoError(suite.test.Apply("../../config/2.configmap.yaml", "", nil))
suite.Require().NoError(suite.test.Apply("../../config/2.configmap.yaml", "", nil))
}

func (suite *CorsSuite) Test_Ingress_Alone() {
Expand Down Expand Up @@ -116,7 +116,7 @@ func (suite *CorsSuite) Default(ingressCors bool) func() {
yamlFile = "config/configmap.yaml.tmpl"
ns = ""
}
suite.NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))
suite.Require().NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))

suite.eventuallyReturns(expectedHeaders, unexpectedHeaders)
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func (suite *CorsSuite) CorsOriginAlone(ingressCors bool) func() {
yamlFile = "config/configmap.yaml.tmpl"
ns = ""
}
suite.NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))
suite.Require().NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))

suite.eventuallyReturns(expectedHeaders, unexpectedHeaders)
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func (suite *CorsSuite) CorsMethodsAlone(ingressCors bool) func() {
yamlFile = "config/configmap.yaml.tmpl"
ns = ""
}
suite.NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))
suite.Require().NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))

suite.eventuallyReturns(expectedHeaders, unexpectedHeaders)
}
Expand Down Expand Up @@ -212,7 +212,7 @@ func (suite *CorsSuite) CorsMethodsHeadersAlone(ingressCors bool) func() {
yamlFile = "config/configmap.yaml.tmpl"
ns = ""
}
suite.NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))
suite.Require().NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))

suite.eventuallyReturns(expectedHeaders, unexpectedHeaders)
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func (suite *CorsSuite) CorsMethodsAgeAlone(ingressCors bool) func() {
yamlFile = "config/configmap.yaml.tmpl"
ns = ""
}
suite.NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))
suite.Require().NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))

suite.eventuallyReturns(expectedHeaders, unexpectedHeaders)
}
Expand Down Expand Up @@ -276,7 +276,7 @@ func (suite *CorsSuite) CorsMethodsCredentialDisable(ingressCors bool) func() {
yamlFile = "config/configmap.yaml.tmpl"
ns = ""
}
suite.NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))
suite.Require().NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))

suite.eventuallyReturns(expectedHeaders, unexpectedHeaders)
}
Expand Down Expand Up @@ -305,7 +305,7 @@ func (suite *CorsSuite) CorsMethodsCredentialAlone(ingressCors bool) func() {
yamlFile = "config/configmap.yaml.tmpl"
ns = ""
}
suite.NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))
suite.Require().NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))

suite.eventuallyReturns(expectedHeaders, http.Header{})
}
Expand Down Expand Up @@ -339,7 +339,7 @@ func (suite *CorsSuite) CorsDisable(ingressCors bool) func() {
yamlFile = "config/configmap.yaml.tmpl"
ns = ""
}
suite.NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))
suite.Require().NoError(suite.test.Apply(yamlFile, ns, suite.tmplData))
suite.eventuallyReturns(http.Header{}, unexpectedHeaders)
}
}
10 changes: 5 additions & 5 deletions deploy/tests/e2e/cors/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ type tmplData struct {
func (suite *CorsSuite) SetupSuite() {
var err error
suite.test, err = e2e.NewTest()
suite.NoError(err)
suite.Require().NoError(err)
suite.tmplData = tmplData{Host: suite.test.GetNS() + ".test"}
suite.client, err = e2e.NewHTTPClient(suite.tmplData.Host)
suite.NoError(err)
suite.Require().NoError(err)

suite.NoError(suite.test.Apply("../../config/2.configmap.yaml", "", nil))
suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), tmplData{Host: suite.test.GetNS() + ".test"}))
suite.Require().NoError(suite.test.Apply("../../config/2.configmap.yaml", "", nil))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), tmplData{Host: suite.test.GetNS() + ".test"}))
}

func (suite *CorsSuite) TearDownSuite() {
// suite.test.Apply("../../config/2.configmap.yaml", "", nil)
suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), tmplData{Host: suite.test.GetNS() + ".test"}))
suite.Require().NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), tmplData{Host: suite.test.GetNS() + ".test"}))
suite.test.TearDown()
}

Expand Down
8 changes: 4 additions & 4 deletions deploy/tests/e2e/crd/cr_global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func (suite *GlobalSuite) Test_CR_Global() {

// Get updated config and do all neede param checks
cfg, err := suite.test.GetIngressControllerFile("/etc/haproxy/haproxy.cfg")
suite.NoError(err, "Could not get Haproxy config")
suite.Require().NoError(err, "Could not get Haproxy config")
reader := strings.NewReader(cfg)
p, err := parser.New(options.Reader(reader))
suite.NoError(err, "Could not get Haproxy config parser")
suite.Require().NoError(err, "Could not get Haproxy config parser")
suite.checkGlobalParam(p, "default-path", &types.DefaultPath{
Type: "config",
})
Expand Down Expand Up @@ -213,12 +213,12 @@ func (suite *GlobalSuite) Test_CR_Global() {

func (suite *GlobalSuite) checkGlobalParam(p parser.Parser, param string, value common.ParserData) {
v, err := p.Get(parser.Global, parser.GlobalSectionName, param)
suite.NoError(err, "Could not get Haproxy config parser Global param %s", param)
suite.Require().NoError(err, "Could not get Haproxy config parser Global param %s", param)
suite.Equal(value, v, fmt.Sprintf("Global param %s should be equal to %v but is %v", param, value, v))
}

func (suite *GlobalSuite) checkLogTargetParam(p parser.Parser, param string, value common.ParserData) {
v, err := p.GetOne(parser.Global, parser.GlobalSectionName, param, 0)
suite.NoError(err, "Could not get Haproxy config parser Global param %s", param)
suite.Require().NoError(err, "Could not get Haproxy config parser Global param %s", param)
suite.Equal(value, v, fmt.Sprintf("Global param %s should be equal to %v but is %v", param, value, v))
}
12 changes: 6 additions & 6 deletions deploy/tests/e2e/crd/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ type tmplData struct {
func (suite *CRDSuite) SetupSuite() {
var err error
suite.test, err = e2e.NewTest()
suite.NoError(err)
suite.Require().NoError(err)
suite.tmplData = tmplData{Host: suite.test.GetNS() + ".test"}
suite.client, err = e2e.NewHTTPClient(suite.tmplData.Host)
suite.NoError(err)
suite.NoError(suite.test.Apply("config/deploy.yaml", suite.test.GetNS(), nil))
suite.NoError(suite.test.Apply("config/ingress.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().NoError(err)
suite.Require().NoError(suite.test.Apply("config/deploy.yaml", suite.test.GetNS(), nil))
suite.Require().NoError(suite.test.Apply("config/ingress.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
suite.Require().Eventually(func() bool {
r, cls, err := suite.client.Do()
if err != nil {
Expand All @@ -72,10 +72,10 @@ func (suite *CRDSuite) TearDownSuite() {

func (suite *CRDSuite) getVersion() int64 {
cfg, err := suite.test.GetIngressControllerFile("/etc/haproxy/haproxy.cfg")
suite.NoError(err, "Could not get Haproxy config")
suite.Require().NoError(err, "Could not get Haproxy config")
reader := strings.NewReader(cfg)
p, err := parser.New(options.Reader(reader))
suite.NoError(err, "Could not get Haproxy config parser")
suite.Require().NoError(err, "Could not get Haproxy config parser")

data, _ := p.Get(parser.Comments, parser.CommentsSectionName, "# _version", false)

Expand Down
Loading

0 comments on commit ea3ffa0

Please sign in to comment.