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 a045d3f commit 80c841f
Show file tree
Hide file tree
Showing 47 changed files with 165 additions and 165 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
4 changes: 2 additions & 2 deletions deploy/tests/e2e/crd-tcp/cr_tcp_additional_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ func (suite *TCPSuiteAddtionalServices) Test_CRD_TCP_Additional_Services() {

// Get updated config and check it
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.checkFrontends(p)

Expand Down
12 changes: 6 additions & 6 deletions deploy/tests/e2e/crd-tcp/cr_tcp_backend_switching_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (suite *TCPSuiteBackendSwitchingRule) Test_CRD_TCP_BackendSwitchingRule() {

// Any other SNI should go to default http-echo
suite.client, err = e2e.NewHTTPSClient("foo.bar", 32766)
suite.NoError(err)
suite.Require().NoError(err)
suite.Eventually(func() bool {
res, cls, err := suite.client.Do()
if res == nil {
Expand All @@ -114,10 +114,10 @@ func (suite *TCPSuiteBackendSwitchingRule) Test_CRD_TCP_BackendSwitchingRule() {

// Get updated config and check it
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")

feName := "tcpcr_e2e-tests-crd-tcp_fe-http-echo"
suite.checkBasicHttpEchoFrontend(p, feName)
Expand All @@ -140,7 +140,7 @@ func (suite *TCPSuiteBackendSwitchingRule) Test_CRD_TCP_BackendSwitchingRule_Wit
// Any other SNI should go to default http-echo
// suite.checkClientRequest("foo.bar", "http-echo-0")
suite.client, err = e2e.NewHTTPSClient("foo.bar", 32766)
suite.NoError(err)
suite.Require().NoError(err)
suite.Eventually(func() bool {
res, cls, err := suite.client.Do()
if res == nil {
Expand All @@ -158,10 +158,10 @@ func (suite *TCPSuiteBackendSwitchingRule) Test_CRD_TCP_BackendSwitchingRule_Wit

// Get updated config and check it
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")

feName := "tcpcr_e2e-tests-crd-tcp_fe-http-echo"
suite.checkBasicHttpEchoFrontend(p, feName)
Expand Down
Loading

0 comments on commit 80c841f

Please sign in to comment.