-
Notifications
You must be signed in to change notification settings - Fork 113
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 <[email protected]>
- Loading branch information
Showing
12 changed files
with
561 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,69 @@ | ||
// 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": key, "Value": 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 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(BeNil()) | ||
Expect(build.Status.Message).To(BeNil()) | ||
}) | ||
|
||
// TODO: add the rest of the combinations | ||
}) | ||
}) |
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,62 @@ | ||
// 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(BeNil()) | ||
Expect(build.Status.Message).To(BeNil()) | ||
}) | ||
|
||
// TODO: add the rest of the combinations | ||
}) | ||
}) |
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,56 @@ | ||
// Copyright The Shipwright Contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package validate_test | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
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("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 node selector is specified", func() { | ||
It("should pass an empty key and empty value", func() { | ||
build := sampleBuild(v1.Toleration{Key: "", Operator: v1.TolerationOpEqual, Value: "", Effect: v1.TaintEffectNoSchedule}) | ||
validate(build) | ||
Expect(build.Status.Reason).To(BeNil()) | ||
Expect(build.Status.Message).To(BeNil()) | ||
}) | ||
|
||
// TODO: add the rest of the combinations | ||
}) | ||
}) |
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
Oops, something went wrong.