Skip to content

Commit

Permalink
revise virt-operator unit test to validate JSON patch type for SCC
Browse files Browse the repository at this point in the history
Signed-off-by: David Vossel <[email protected]>
  • Loading branch information
davidvossel committed May 14, 2019
1 parent 372876c commit af02869
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions pkg/virt-operator/kubevirt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package virt_operator

import (
"encoding/json"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -847,15 +846,13 @@ var _ = Describe("KubeVirt Operator", func() {
}
return true, nil, nil
}
expectUsers := func(userBytes []byte, count int) {

type _users struct {
Users []string `json:"users"`
}
users := &_users{}

json.Unmarshal(userBytes, users)
ExpectWithOffset(2, len(users.Users)).To(Equal(count))
expectUsersDeleted := func(userBytes []byte) {
deletePatch := `[ { "op": "test", "path": "/users", "value": ["someUser","system:serviceaccount:kubevirt-test:kubevirt-handler","system:serviceaccount:kubevirt-test:kubevirt-apiserver","system:serviceaccount:kubevirt-test:kubevirt-controller"] }, { "op": "replace", "path": "/users", "value": ["someUser"] } ]`
Expect(userBytes).To(Equal([]byte(deletePatch)))
}
expectUsersAdded := func(userBytes []byte) {
addPatch := `[ { "op": "test", "path": "/users", "value": ["someUser"] }, { "op": "replace", "path": "/users", "value": ["someUser","system:serviceaccount:kubevirt-test:kubevirt-handler","system:serviceaccount:kubevirt-test:kubevirt-apiserver","system:serviceaccount:kubevirt-test:kubevirt-controller"] } ]`
Expect(userBytes).To(Equal([]byte(addPatch)))
}

shouldExpectInstallStrategyDeletion := func() {
Expand All @@ -882,7 +879,7 @@ var _ = Describe("KubeVirt Operator", func() {

secClient.Fake.PrependReactor("patch", "securitycontextconstraints", func(action testing.Action) (handled bool, obj runtime.Object, err error) {
patch, _ := action.(testing.PatchAction)
expectUsers(patch.GetPatch(), 1)
expectUsersDeleted(patch.GetPatch())
return true, nil, nil
})
extClient.Fake.PrependReactor("delete", "customresourcedefinitions", genericDeleteFunc)
Expand Down Expand Up @@ -930,7 +927,7 @@ var _ = Describe("KubeVirt Operator", func() {

secClient.Fake.PrependReactor("patch", "securitycontextconstraints", func(action testing.Action) (handled bool, obj runtime.Object, err error) {
patch, _ := action.(testing.PatchAction)
expectUsers(patch.GetPatch(), 4)
expectUsersAdded(patch.GetPatch())
return true, nil, nil
})
extClient.Fake.PrependReactor("create", "customresourcedefinitions", genericCreateFunc)
Expand Down

0 comments on commit af02869

Please sign in to comment.