summaryrefslogtreecommitdiffstats
path: root/extras/hs-test/infra
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2024-08-26 18:01:14 +0200
committerMatus Fabian <matfabia@cisco.com>2024-08-26 18:03:31 +0200
commita647a83496f81a83c02fe9317955a781b7f95d8c (patch)
treede2c54b572d7d2a725b5b55b442178b2dca020b2 /extras/hs-test/infra
parent62b508b396b4bcca37b934247ea04f5efef85354 (diff)
hs-test: http tests improvement
- added http specific asserts - added helper functions to NoTopoSuite Type: test Change-Id: I0a7e77ed3ffd938aa3eaa37ed5432fbaab0dab64 Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'extras/hs-test/infra')
-rw-r--r--extras/hs-test/infra/container.go2
-rw-r--r--extras/hs-test/infra/hst_suite.go31
-rw-r--r--extras/hs-test/infra/suite_no_topo.go12
3 files changed, 43 insertions, 2 deletions
diff --git a/extras/hs-test/infra/container.go b/extras/hs-test/infra/container.go
index a9069d756c4..974d1547c03 100644
--- a/extras/hs-test/infra/container.go
+++ b/extras/hs-test/infra/container.go
@@ -313,7 +313,7 @@ func (c *Container) Run() {
func (c *Container) addVolume(hostDir string, containerDir string, isDefaultWorkDir bool) {
var volume Volume
- volume.HostDir = strings.Replace(hostDir, "volumes", c.Suite.GetTestId() + "/" + "volumes", 1)
+ volume.HostDir = strings.Replace(hostDir, "volumes", c.Suite.GetTestId()+"/"+"volumes", 1)
volume.ContainerDir = containerDir
volume.IsDefaultWorkDir = isDefaultWorkDir
c.Volumes[hostDir] = volume
diff --git a/extras/hs-test/infra/hst_suite.go b/extras/hs-test/infra/hst_suite.go
index 82734be9f3d..5c124d3b210 100644
--- a/extras/hs-test/infra/hst_suite.go
+++ b/extras/hs-test/infra/hst_suite.go
@@ -14,6 +14,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
+ "strconv"
"strings"
"time"
@@ -258,7 +259,35 @@ func (s *HstSuite) AssertNotEmpty(object interface{}, msgAndArgs ...interface{})
}
func (s *HstSuite) AssertMatchError(actual, expected error, msgAndArgs ...interface{}) {
- ExpectWithOffset(2, actual).To(MatchError(expected))
+ ExpectWithOffset(2, actual).To(MatchError(expected), msgAndArgs...)
+}
+
+func (s *HstSuite) AssertGreaterThan(actual, expected interface{}, msgAndArgs ...interface{}) {
+ ExpectWithOffset(2, actual).Should(BeNumerically(">=", expected), msgAndArgs...)
+}
+
+func (s *HstSuite) AssertTimeEqualWithinThreshold(actual, expected time.Time, threshold time.Duration, msgAndArgs ...interface{}) {
+ ExpectWithOffset(2, actual).Should(BeTemporally("~", expected, threshold), msgAndArgs...)
+}
+
+func (s *HstSuite) AssertHttpStatus(resp *http.Response, expectedStatus int, msgAndArgs ...interface{}) {
+ ExpectWithOffset(2, resp).To(HaveHTTPStatus(expectedStatus), msgAndArgs...)
+}
+
+func (s *HstSuite) AssertHttpHeaderWithValue(resp *http.Response, key string, value interface{}, msgAndArgs ...interface{}) {
+ ExpectWithOffset(2, resp).To(HaveHTTPHeaderWithValue(key, value), msgAndArgs...)
+}
+
+func (s *HstSuite) AssertHttpHeaderNotPresent(resp *http.Response, key string, msgAndArgs ...interface{}) {
+ ExpectWithOffset(2, resp.Header.Get(key)).To(BeEmpty(), msgAndArgs...)
+}
+
+func (s *HstSuite) AssertHttpContentLength(resp *http.Response, expectedContentLen int64, msgAndArgs ...interface{}) {
+ ExpectWithOffset(2, resp).To(HaveHTTPHeaderWithValue("Content-Length", strconv.FormatInt(expectedContentLen, 10)), msgAndArgs...)
+}
+
+func (s *HstSuite) AssertHttpBody(resp *http.Response, expectedBody string, msgAndArgs ...interface{}) {
+ ExpectWithOffset(2, resp).To(HaveHTTPBody(expectedBody), msgAndArgs...)
}
func (s *HstSuite) CreateLogger() {
diff --git a/extras/hs-test/infra/suite_no_topo.go b/extras/hs-test/infra/suite_no_topo.go
index 5f53f55f1bb..9b4998a77a1 100644
--- a/extras/hs-test/infra/suite_no_topo.go
+++ b/extras/hs-test/infra/suite_no_topo.go
@@ -60,6 +60,18 @@ func (s *NoTopoSuite) SetupTest() {
s.AssertNil(vpp.createTap(tapInterface), "failed to create tap interface")
}
+func (s *NoTopoSuite) VppAddr() string {
+ return s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
+}
+
+func (s *NoTopoSuite) VppIfName() string {
+ return s.GetInterfaceByName(TapInterfaceName).Peer.Name()
+}
+
+func (s *NoTopoSuite) HostAddr() string {
+ return s.GetInterfaceByName(TapInterfaceName).Ip4AddressString()
+}
+
var _ = Describe("NoTopoSuite", Ordered, ContinueOnFailure, func() {
var s NoTopoSuite
BeforeAll(func() {