Skip to content

Commit

Permalink
add a test to test-cmd.sh for apply -f with label selector
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedanese committed Sep 30, 2016
1 parent 5f2569c commit 6339d91
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
15 changes: 15 additions & 0 deletions hack/make-rules/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,21 @@ __EOF__
# Clean up
kubectl delete pods test-pod "${kube_flags[@]}"


## kubectl apply -f with label selector should only apply matching objects
# Pre-Condition: no POD exists
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
# apply
kubectl apply -l unique-label=bingbang -f hack/testdata/filter "${kube_flags[@]}"
# check right pod exists
kube::test::get_object_assert 'pods selector-test-pod' "{{${labels_field}.name}}" 'selector-test-pod'
# check wrong pod doesn't exist
output_message=$(! kubectl get pods selector-test-pod-dont-apply 2>&1 "${kube_flags[@]}")
kube::test::if_has_string "${output_message}" 'pods "selector-test-pod-dont-apply" not found'
# cleanup
kubectl delete pods selector-test-pod


## kubectl run should create deployments or jobs
# Pre-Condition: no Job exists
kube::test::get_object_assert jobs "{{range.items}}{{$id_field}}:{{end}}" ''
Expand Down
11 changes: 11 additions & 0 deletions hack/testdata/filter/pod-apply-selector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
name: selector-test-pod
labels:
name: selector-test-pod
unique-label: bingbang
spec:
containers:
- name: kubernetes-pause
image: gcr.io/google-containers/pause:2.0
11 changes: 11 additions & 0 deletions hack/testdata/filter/pod-dont-apply.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
name: selector-test-pod-dont-apply
labels:
name: selector-test-pod-dont-apply
unique-label: biz
spec:
containers:
- name: kubernetes-pause
image: gcr.io/google-containers/pause:2.0

0 comments on commit 6339d91

Please sign in to comment.