Skip to content

Commit

Permalink
connectivity: Add WithCiliumVersion
Browse files Browse the repository at this point in the history
It's going to be used to skip some tests based on Cilium vsn.

Signed-off-by: Martynas Pumputis <[email protected]>
  • Loading branch information
brb committed May 17, 2023
1 parent e14e1bb commit 9b347f2
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion connectivity/check/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
"sync"
"time"

"github.com/blang/semver/v4"
k8sConst "github.com/cilium/cilium/pkg/k8s/apis/cilium.io"
ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
"github.com/cilium/cilium/pkg/versioncheck"

"github.com/cilium/cilium-cli/defaults"
"github.com/cilium/cilium-cli/sysdump"
Expand Down Expand Up @@ -66,6 +68,9 @@ type Test struct {
// for this test to be run
requirements []FeatureRequirement

// requiredCiliumVSN is a required Cilium VSN for this test to be run
requiredCiliumVSN semver.Range

// Scenarios registered to this test.
scenarios map[Scenario][]*Action

Expand Down Expand Up @@ -167,14 +172,19 @@ func (t *Test) skip(s Scenario) {
}

// willRun returns false if all of the Test's Scenarios will be skipped, or
// if any of its FeatureRequirements does not match
// if any of its FeatureRequirements does not match, or a required Cilium vsn
// does not match.
func (t *Test) willRun() bool {
var sc int

if !t.Context().features.MatchRequirements(t.requirements...) {
return false
}

if t.requiredCiliumVSN != nil && !t.requiredCiliumVSN(t.Context().CiliumVersion) {
return false
}

for s := range t.scenarios {
if !t.Context().params.testEnabled(t.scenarioName(s)) {
sc++
Expand Down Expand Up @@ -469,6 +479,14 @@ func (t *Test) WithFeatureRequirements(reqs ...FeatureRequirement) *Test {
return t
}

// WithCiliumVersion adds a requirement for a Cilium vsn in order for the test
// to run.
func (t *Test) WithCiliumVersion(vsn string) *Test {
t.requiredCiliumVSN = versioncheck.MustCompile(vsn)

return t
}

// WithSecret takes a Secret and adds it to the cluster during the test
func (t *Test) WithSecret(secret *corev1.Secret) *Test {

Expand Down

0 comments on commit 9b347f2

Please sign in to comment.