Skip to content

Commit 2734e94

Browse files
committed
test: add go test and bats tests
- test: OK Signed-off-by: rxinui <[email protected]>
1 parent abcd2ff commit 2734e94

7 files changed

+84
-2
lines changed

docs/shp_build_create.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ shp build create <name> [flags]
3030
--retention-succeeded-limit uint number of succeeded BuildRuns to be kept (default 65535)
3131
--retention-ttl-after-failed duration duration to delete a failed BuildRun after completion
3232
--retention-ttl-after-succeeded duration duration to delete a succeeded BuildRun after completion
33+
--scheduler-name string specify the scheduler to be used to dispatch the Pod
3334
--source-context-dir string use a inner directory as context directory
3435
--source-git-clone-secret string name of the secret with credentials to access the git source, e.g. git credentials
3536
--source-git-revision string git repository source revision

docs/shp_build_run.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ shp build run <name> [flags]
3232
--retention-ttl-after-failed duration duration to delete the BuildRun after it failed
3333
--retention-ttl-after-succeeded duration duration to delete the BuildRun after it succeeded
3434
--sa-name string Kubernetes service-account name
35+
--scheduler-name string specify the scheduler to be used to dispatch the Pod
3536
--timeout duration build process timeout
3637
```
3738

docs/shp_build_upload.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ shp build upload <build-name> [path/to/source|.] [flags]
4242
--retention-ttl-after-failed duration duration to delete the BuildRun after it failed
4343
--retention-ttl-after-succeeded duration duration to delete the BuildRun after it succeeded
4444
--sa-name string Kubernetes service-account name
45+
--scheduler-name string specify the scheduler to be used to dispatch the Pod
4546
--timeout duration build process timeout
4647
```
4748

docs/shp_buildrun_create.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ shp buildrun create <name> [flags]
3131
--retention-ttl-after-failed duration duration to delete the BuildRun after it failed
3232
--retention-ttl-after-succeeded duration duration to delete the BuildRun after it succeeded
3333
--sa-name string Kubernetes service-account name
34+
--scheduler-name string specify the scheduler to be used to dispatch the Pod
3435
--timeout duration build process timeout
3536
```
3637

pkg/shp/flags/build_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ func TestBuildSpecFromFlags(t *testing.T) {
5555
Duration: 30 * time.Minute,
5656
},
5757
},
58-
NodeSelector: map[string]string{"kubernetes.io/hostname": "worker-1"},
58+
NodeSelector: map[string]string{"kubernetes.io/hostname": "worker-1"},
59+
SchedulerName: ptr.To("dolphinscheduler"),
5960
}
6061

6162
cmd := &cobra.Command{}
@@ -123,6 +124,13 @@ func TestBuildSpecFromFlags(t *testing.T) {
123124
g.Expect(expected.NodeSelector).To(o.Equal(spec.NodeSelector), ".spec.nodeSelector")
124125
})
125126

127+
t.Run(".spec.schedulerName", func(_ *testing.T) {
128+
err := flags.Set(SchedulerNameFlag, *expected.SchedulerName)
129+
g.Expect(err).To(o.BeNil())
130+
131+
g.Expect(expected.SchedulerName).To(o.Equal(spec.SchedulerName), "spec.schedulerName")
132+
})
133+
126134
t.Run(".spec.timeout", func(_ *testing.T) {
127135
err := flags.Set(TimeoutFlag, expected.Timeout.Duration.String())
128136
g.Expect(err).To(o.BeNil())

pkg/shp/flags/buildrun_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ func TestBuildRunSpecFromFlags(t *testing.T) {
3838
Duration: 30 * time.Minute,
3939
},
4040
},
41-
NodeSelector: map[string]string{"kubernetes.io/hostname": "worker-1"},
41+
NodeSelector: map[string]string{"kubernetes.io/hostname": "worker-1"},
42+
SchedulerName: ptr.To("dolphinscheduler"),
4243
}
4344

4445
cmd := &cobra.Command{}
@@ -83,6 +84,13 @@ func TestBuildRunSpecFromFlags(t *testing.T) {
8384
g.Expect(expected.NodeSelector).To(o.Equal(spec.NodeSelector), ".spec.nodeSelector")
8485
})
8586

87+
t.Run(".spec.schedulerName", func(_ *testing.T) {
88+
err := flags.Set(SchedulerNameFlag, *expected.SchedulerName)
89+
g.Expect(err).To(o.BeNil())
90+
91+
g.Expect(expected.SchedulerName).To(o.Equal(spec.SchedulerName), "spec.schedulerName")
92+
})
93+
8694
t.Run(".spec.retention.ttlAfterFailed", func(_ *testing.T) {
8795
err := flags.Set(RetentionTTLAfterFailedFlag, expected.Retention.TTLAfterFailed.Duration.String())
8896
g.Expect(err).To(o.BeNil())

test/e2e/node-selector.bats

+62
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ teardown() {
1313
run kubectl delete buildruns.shipwright.io --all
1414
}
1515

16+
scheduler_name="dolphinscheduler"
17+
1618
@test "shp build create --node-selector single label" {
1719
# generate random names for our build
1820
build_name=$(random_name)
@@ -50,6 +52,24 @@ teardown() {
5052
assert_output --partial '"kubernetes.io/os":"linux"'
5153
}
5254

55+
@test "shp build create --scheduler-name" {
56+
# generate random names for our build
57+
build_name=$(random_name)
58+
59+
# create a Build with node selector
60+
run shp build create ${build_name} --source-git-url=https://github.com/shipwright-io/sample-go --output-image=my-fake-image --scheduler-name=${scheduler_name}
61+
assert_success
62+
63+
# ensure that the build was successfully created
64+
assert_output --partial "Created build \"${build_name}\""
65+
66+
# get the jsonpath of Build object .spec.nodeSelector
67+
run kubectl get builds.shipwright.io/${build_name} -ojsonpath="{.spec.schedulerName}"
68+
assert_success
69+
70+
assert_output "${scheduler_name}"
71+
}
72+
5373
@test "shp buildrun create --node-selector single label" {
5474
# generate random names for our buildrun
5575
buildrun_name=$(random_name)
@@ -89,6 +109,25 @@ teardown() {
89109
assert_output --partial '"kubernetes.io/os":"linux"'
90110
}
91111

112+
@test "shp buildrun create --scheduler-name" {
113+
# generate random names for our buildrun
114+
buildrun_name=$(random_name)
115+
build_name=$(random_name)
116+
117+
# create a Build with node selector
118+
run shp buildrun create ${buildrun_name} --buildref-name=${build_name} --scheduler-name=${scheduler_name}
119+
assert_success
120+
121+
# ensure that the build was successfully created
122+
assert_output --partial "BuildRun created \"${buildrun_name}\" for Build \"${build_name}\""
123+
124+
# get the jsonpath of Build object .spec.nodeSelector
125+
run kubectl get buildruns.shipwright.io/${buildrun_name} -ojsonpath="{.spec.schedulerName}"
126+
assert_success
127+
128+
assert_output "${scheduler_name}"
129+
}
130+
92131

93132
@test "shp build run --node-selector set" {
94133
# generate random names for our build
@@ -111,4 +150,27 @@ teardown() {
111150
run kubectl get buildruns.shipwright.io -ojsonpath='{.items[*].spec.nodeSelector}'
112151
assert_success
113152
assert_output --partial '"kubernetes.io/hostname":"node-1"'
153+
}
154+
155+
@test "shp build run --scheduler-name" {
156+
# generate random names for our build
157+
build_name=$(random_name)
158+
159+
# create a Build with node selector
160+
run shp build create ${build_name} --source-git-url=https://github.com/shipwright-io/sample-go --output-image=my-fake-image
161+
assert_success
162+
163+
# ensure that the build was successfully created
164+
assert_output --partial "Created build \"${build_name}\""
165+
166+
# get the build object
167+
run kubectl get builds.shipwright.io/${build_name}
168+
assert_success
169+
170+
run shp build run ${build_name} --scheduler-name=${scheduler_name}
171+
172+
# get the jsonpath of Build object .spec.nodeSelector
173+
run kubectl get buildruns.shipwright.io -ojsonpath='{.items[*].spec.schedulerName}'
174+
assert_success
175+
assert_output --partial "${scheduler_name}"
114176
}

0 commit comments

Comments
 (0)