-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for Custom Scheduler Name on Build and BuildRun objects
Signed-off-by: Dylan Orzel <dorzel@redhat.com>
- Loading branch information
Showing
12 changed files
with
649 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright The Shipwright Contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package validate_test | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
corev1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
. "github.com/shipwright-io/build/pkg/apis/build/v1beta1" | ||
"github.com/shipwright-io/build/pkg/validate" | ||
) | ||
|
||
var _ = Describe("ValidateNodeSelector", func() { | ||
var ctx context.Context | ||
|
||
BeforeEach(func() { | ||
ctx = context.TODO() | ||
}) | ||
|
||
var validate = func(build *Build) { | ||
GinkgoHelper() | ||
|
||
var validator = &validate.NodeSelectorRef{Build: build} | ||
Expect(validator.ValidatePath(ctx)).To(Succeed()) | ||
} | ||
|
||
var sampleBuild = func(key string, value string) *Build { | ||
return &Build{ | ||
ObjectMeta: corev1.ObjectMeta{ | ||
Namespace: "foo", | ||
Name: "bar", | ||
}, | ||
Spec: BuildSpec{ | ||
NodeSelector: map[string]string{key: value}, | ||
}, | ||
} | ||
} | ||
|
||
Context("when node selector is specified", func() { | ||
It("should pass an empty key and value", func() { | ||
build := sampleBuild("", "") | ||
validate(build) | ||
Expect(build.Status.Reason).To(BeNil()) | ||
Expect(build.Status.Message).To(BeNil()) | ||
}) | ||
|
||
It("should pass a valid key and valid value", func() { | ||
build := sampleBuild("validkey", "validvalue") | ||
validate(build) | ||
Expect(build.Status.Reason).To(BeNil()) | ||
Expect(build.Status.Message).To(BeNil()) | ||
}) | ||
|
||
It("should pass an empty key and valid value", func() { | ||
build := sampleBuild("", "validvalue") | ||
validate(build) | ||
Expect(build.Status.Reason).To(BeNil()) | ||
Expect(build.Status.Message).To(BeNil()) | ||
}) | ||
|
||
It("should fail an empty key and invalid value", func() { | ||
build := sampleBuild("", "invalidvalue!") | ||
validate(build) | ||
Expect(*build.Status.Reason).To(Equal(NodeSelectorNotValid)) | ||
Expect(*build.Status.Message).To(ContainSubstring("Node selector value not valid")) | ||
}) | ||
|
||
It("should fail an invalid key and empty value", func() { | ||
build := sampleBuild("invalidkey!", "") | ||
validate(build) | ||
Expect(*build.Status.Reason).To(Equal(NodeSelectorNotValid)) | ||
Expect(*build.Status.Message).To(ContainSubstring("Node selector key not valid")) | ||
}) | ||
|
||
It("should fail both an invalid key and invalid value", func() { | ||
build := sampleBuild("invalidkey!", "invalidvalue!") | ||
validate(build) | ||
Expect(*build.Status.Reason).To(Equal(NodeSelectorNotValid)) | ||
Expect(*build.Status.Message).To(ContainSubstring("Node selector key not valid")) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright The Shipwright Contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package validate_test | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
corev1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
. "github.com/shipwright-io/build/pkg/apis/build/v1beta1" | ||
"github.com/shipwright-io/build/pkg/validate" | ||
) | ||
|
||
var _ = Describe("ValidateSchedulerName", func() { | ||
var ctx context.Context | ||
|
||
BeforeEach(func() { | ||
ctx = context.TODO() | ||
}) | ||
|
||
var validate = func(build *Build) { | ||
GinkgoHelper() | ||
|
||
var validator = &validate.SchedulerNameRef{Build: build} | ||
Expect(validator.ValidatePath(ctx)).To(Succeed()) | ||
} | ||
|
||
var sampleBuild = func(schedulerName string) *Build { | ||
return &Build{ | ||
ObjectMeta: corev1.ObjectMeta{ | ||
Namespace: "foo", | ||
Name: "bar", | ||
}, | ||
Spec: BuildSpec{ | ||
SchedulerName: schedulerName, | ||
}, | ||
} | ||
} | ||
|
||
Context("when schedulerName is specified", func() { | ||
It("should pass an empty name", func() { | ||
build := sampleBuild("") | ||
validate(build) | ||
Expect(build.Status.Reason).To(BeNil()) | ||
Expect(build.Status.Message).To(BeNil()) | ||
}) | ||
|
||
It("should fail an invalid name", func() { | ||
build := sampleBuild("invalidname!") | ||
validate(build) | ||
Expect(*build.Status.Reason).To(Equal(SchedulerNameNotValid)) | ||
Expect(*build.Status.Message).To(ContainSubstring("Scheduler name not valid")) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Copyright The Shipwright Contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package validate_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
corev1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/validation" | ||
"k8s.io/utils/ptr" | ||
|
||
. "github.com/shipwright-io/build/pkg/apis/build/v1beta1" | ||
"github.com/shipwright-io/build/pkg/validate" | ||
) | ||
|
||
var _ = Describe("ValidateTolerations", func() { | ||
var ctx context.Context | ||
|
||
BeforeEach(func() { | ||
ctx = context.TODO() | ||
}) | ||
|
||
var validate = func(build *Build) { | ||
GinkgoHelper() | ||
|
||
var validator = &validate.TolerationsRef{Build: build} | ||
Expect(validator.ValidatePath(ctx)).To(Succeed()) | ||
} | ||
|
||
var sampleBuild = func(toleration v1.Toleration) *Build { | ||
return &Build{ | ||
ObjectMeta: corev1.ObjectMeta{ | ||
Namespace: "foo", | ||
Name: "bar", | ||
}, | ||
Spec: BuildSpec{ | ||
Tolerations: []v1.Toleration{toleration}, | ||
}, | ||
} | ||
} | ||
|
||
Context("when tolerations is specified", func() { | ||
It("should fail an empty key and empty value", func() { | ||
build := sampleBuild(v1.Toleration{Key: "", Value: "", Operator: v1.TolerationOpEqual, Effect: v1.TaintEffectNoSchedule}) | ||
validate(build) | ||
Expect(*build.Status.Reason).To(Equal(TolerationNotValid)) | ||
Expect(*build.Status.Message).To(ContainSubstring(validation.EmptyError())) | ||
}) | ||
|
||
It("should pass a valid key and valid value", func() { | ||
build := sampleBuild(v1.Toleration{Key: "validkey", Value: "validvalue", Operator: v1.TolerationOpEqual, Effect: v1.TaintEffectNoSchedule}) | ||
validate(build) | ||
Expect(build.Status.Reason).To(BeNil()) | ||
Expect(build.Status.Message).To(BeNil()) | ||
}) | ||
|
||
It("should pass a valid key and empty value", func() { | ||
build := sampleBuild(v1.Toleration{Key: "validkey", Value: "", Operator: v1.TolerationOpEqual, Effect: v1.TaintEffectNoSchedule}) | ||
validate(build) | ||
Expect(build.Status.Reason).To(BeNil()) | ||
Expect(build.Status.Message).To(BeNil()) | ||
}) | ||
|
||
It("should fail an invalid key and empty value", func() { | ||
build := sampleBuild(v1.Toleration{Key: "invalidkey!", Value: "", Operator: v1.TolerationOpEqual, Effect: v1.TaintEffectNoSchedule}) | ||
validate(build) | ||
Expect(*build.Status.Reason).To(Equal(TolerationNotValid)) | ||
Expect(*build.Status.Message).To(ContainSubstring("Toleration key not valid")) | ||
}) | ||
|
||
It("should fail an invalid key and invalid value", func() { | ||
build := sampleBuild(v1.Toleration{Key: "invalidkey!", Value: "invalidvalue!", Operator: v1.TolerationOpEqual, Effect: v1.TaintEffectNoSchedule}) | ||
validate(build) | ||
Expect(*build.Status.Reason).To(Equal(TolerationNotValid)) | ||
Expect(*build.Status.Message).To(ContainSubstring("Toleration key not valid")) | ||
}) | ||
|
||
It("should fail a valid key and invalid value", func() { | ||
build := sampleBuild(v1.Toleration{Key: "validkey", Value: "invalidvalue!", Operator: v1.TolerationOpEqual, Effect: v1.TaintEffectNoSchedule}) | ||
validate(build) | ||
Expect(*build.Status.Reason).To(Equal(TolerationNotValid)) | ||
Expect(*build.Status.Message).To(ContainSubstring("Toleration value not valid")) | ||
}) | ||
|
||
It("should fail an invalid operator", func() { | ||
build := sampleBuild(v1.Toleration{Key: "validkey", Value: "validvalue", Operator: "invalidoperator", Effect: v1.TaintEffectNoSchedule}) | ||
validate(build) | ||
Expect(*build.Status.Reason).To(Equal(TolerationNotValid)) | ||
Expect(*build.Status.Message).To(ContainSubstring("Toleration operator not valid")) | ||
}) | ||
|
||
It("should pass an empty taint effect", func() { | ||
build := sampleBuild(v1.Toleration{Key: "validkey", Value: "validvalue", Operator: v1.TolerationOpEqual, Effect: ""}) | ||
validate(build) | ||
Expect(build.Status.Reason).To(BeNil()) | ||
Expect(build.Status.Message).To(BeNil()) | ||
}) | ||
|
||
It("should pass a taint effect of NoSchedule", func() { | ||
build := sampleBuild(v1.Toleration{Key: "validkey", Value: "validvalue", Operator: v1.TolerationOpEqual, Effect: v1.TaintEffectNoSchedule}) | ||
validate(build) | ||
Expect(build.Status.Reason).To(BeNil()) | ||
Expect(build.Status.Message).To(BeNil()) | ||
}) | ||
|
||
It("should fail an invalid taint effect", func() { | ||
build := sampleBuild(v1.Toleration{Key: "validkey", Value: "validvalue", Operator: v1.TolerationOpEqual, Effect: v1.TaintEffectNoExecute}) | ||
validate(build) | ||
Expect(*build.Status.Reason).To(Equal(TolerationNotValid)) | ||
Expect(*build.Status.Message).To(ContainSubstring(fmt.Sprintf("Only the '%v' toleration effect is supported.", v1.TaintEffectNoSchedule))) | ||
}) | ||
|
||
It("should fail specifying tolerationSeconds", func() { | ||
build := sampleBuild(v1.Toleration{Key: "validkey", Value: "validvalue", Operator: v1.TolerationOpEqual, Effect: v1.TaintEffectNoSchedule, TolerationSeconds: ptr.To(int64(10))}) | ||
validate(build) | ||
Expect(*build.Status.Reason).To(Equal(TolerationNotValid)) | ||
Expect(*build.Status.Message).To(ContainSubstring("Specifying TolerationSeconds is not supported")) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.