Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ linters:
staticcheck:
dot-import-whitelist:
- "github.com/onsi/ginkgo"
- "github.com/onsi/ginkgo/v2"
- "github.com/onsi/gomega"
checks:
- all
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ ci-test: builder-image
-v /tmp/services-tests-vpp:/tmp/services-tests-vpp \
-v /tmp/felix-tests-vpp:/tmp/felix-tests-vpp \
-v /tmp/prometheus-tests-vpp:/tmp/prometheus-tests-vpp \
-v /tmp/vpp-test-vpp-manager-test:/tmp/vpp-test-vpp-manager-test \
-v /var/run/docker.sock:/var/run/docker.sock \
--env VPP_BINARY=/usr/bin/vpp \
--env VPP_IMAGE=calicovpp/vpp:$(TAG) \
Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/inconshreveable/mousetrap v1.1.0
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0
github.com/onsi/ginkgo v1.16.5
github.com/onsi/ginkgo/v2 v2.25.1
github.com/onsi/gomega v1.38.1
github.com/orijtech/prometheus-go-metrics-exporter v0.0.6
github.com/osrg/gobgp/v3 v3.35.0
Expand All @@ -35,6 +36,7 @@ require (
)

require (
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/bennyscetbun/jsongo v1.1.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand All @@ -56,12 +58,14 @@ require (
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.9 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/pprof v0.0.0-20250820193118-f64d9cf942d6 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
Expand Down Expand Up @@ -98,6 +102,7 @@ require (
go.etcd.io/etcd/client/pkg/v3 v3.6.4 // indirect
go.etcd.io/etcd/client/v3 v3.6.4 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
Expand All @@ -109,6 +114,7 @@ require (
golang.org/x/term v0.37.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/time v0.14.0 // indirect
golang.org/x/tools v0.38.0 // indirect
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20241231184526-a9ab2273dd10 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250721164621-a45f3dfb1074 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250811230008-5f3141c8851a // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/Nu
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
Expand Down Expand Up @@ -219,6 +218,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/projectcalico/api v0.0.0-20251022175904-f2ab03771208 h1:ltTWo/cCc/8pEpzmlzIjt6r2383x2XDPkuBcd/9kE3k=
github.com/projectcalico/api v0.0.0-20251022175904-f2ab03771208/go.mod h1:0+91//9pw8kMOyWwG1egVY9a9y43kVTLZfiEF1l5IQc=
github.com/projectcalico/calico v0.0.0-20251021213802-b1f3c43f8437 h1:PbLe6D0Yis8ce4F+o/Dmlrv4Her2ZN6ns8rmlZoFoEY=
Expand Down
54 changes: 54 additions & 0 deletions pkg/testutils/assertions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (C) 2025 Cisco Systems Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package testutils

import (
. "github.com/onsi/gomega"

"github.com/projectcalico/vpp-dataplane/v3/vpplink"
)

// VppAssertions provides assertion helpers for VPP state
type VppAssertions struct {
vpp *vpplink.VppLink
}

// NewVppAssertions creates a new VppAssertions helper
func NewVppAssertions(vpp *vpplink.VppLink) *VppAssertions {
return &VppAssertions{vpp: vpp}
}

// AssertInterfaceIsUp checks that an interface is administratively up
func (a *VppAssertions) AssertInterfaceIsUp(swIfIndex uint32) {
details, err := a.vpp.GetInterfaceDetails(swIfIndex)
Expect(err).ToNot(HaveOccurred(), "failed to dump interfaces")
Expect(details.IsUp).To(BeTrue(), "interface is not admin up")
}

// AssertMemifInterfaceExists checks that a memif interface exists
func (a *VppAssertions) AssertMemifInterfaceExists(swIfIndex uint32) {
memifs, err := a.vpp.ListMemifInterfaces()
Expect(err).ToNot(HaveOccurred(), "failed to dump memif interfaces")

found := false
for _, memif := range memifs {
if memif.SwIfIndex == swIfIndex {
found = true
break
}
}
Expect(found).To(BeTrue(), "memif interface %d not found", swIfIndex)
}
56 changes: 56 additions & 0 deletions pkg/testutils/fixtures.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (C) 2025 Cisco Systems Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package testutils

import (
"fmt"

"github.com/sirupsen/logrus"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

// VppFixture is a Ginkgo fixture to setup and teardown VPP instances in tests
type VppFixture struct {
Instance *VppInstance
Config VppConfig
}

// Setup initializes the VPP fixture
func (f *VppFixture) Setup(name, image, binary string, log *logrus.Logger) {
if f.Config.WorkersCount == 0 && len(f.Config.EnablePlugins) == 0 {
f.Config = DefaultVppConfig()
}

f.Instance = NewVppInstance(name, image, binary, f.Config, log)

By(fmt.Sprintf("Starting VPP instance: %s", name))
err := f.Instance.Start()
Expect(err).ToNot(HaveOccurred(), "failed to start VPP")

By(fmt.Sprintf("Connecting to VPP instance: %s", name))
_, err = f.Instance.Connect()
Expect(err).ToNot(HaveOccurred(), "failed to connect to VPP")
}

// Teardown cleans up the VPP fixture
func (f *VppFixture) Teardown() {
if f.Instance != nil {
By(fmt.Sprintf("Stopping VPP instance: %s", f.Instance.Name))
_ = f.Instance.Stop()
}
}
29 changes: 29 additions & 0 deletions pkg/testutils/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2025 Cisco Systems Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package testutils

import (
"net"

. "github.com/onsi/gomega"
)

// ParseMAC is a helper to parse MAC address
func ParseMAC(macStr string) net.HardwareAddr {
mac, err := net.ParseMAC(macStr)
Expect(err).ToNot(HaveOccurred(), "invalid MAC address")
return mac
}
40 changes: 40 additions & 0 deletions pkg/testutils/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (C) 2025 Cisco Systems Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package testutils

import (
. "github.com/onsi/ginkgo/v2"
)

// LogSection logs a section header.
func LogSection(title string) {
GinkgoWriter.Printf("\n=== %s ===\n", title)
}

// LogStep logs a test step with arrow prefix.
func LogStep(format string, args ...interface{}) {
GinkgoWriter.Printf(" → "+format+"\n", args...)
}

// LogSuccess logs a success message with checkmark prefix.
func LogSuccess(format string, args ...interface{}) {
GinkgoWriter.Printf(" ✓ "+format+"\n", args...)
}

// LogInfo logs an info message.
func LogInfo(format string, args ...interface{}) {
GinkgoWriter.Printf(" "+format+"\n", args...)
}
Loading
Loading