github.com/mkimuram/operator-sdk@v0.7.1-0.20190410172100-52ad33a4bda0/cmd/operator-sdk/build/build_test.go (about) 1 // Copyright 2018 The Operator-SDK Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package build 16 17 import "testing" 18 19 var memcachedNamespaceManExample = `apiVersion: v1 20 kind: ServiceAccount 21 metadata: 22 name: memcached-operator 23 24 --- 25 26 kind: Role 27 apiVersion: rbac.authorization.k8s.io/v1beta1 28 metadata: 29 name: memcached-operator 30 rules: 31 - apiGroups: 32 - cache.example.com 33 resources: 34 - "*" 35 verbs: 36 - "*" 37 - apiGroups: 38 - "" 39 resources: 40 - pods 41 - services 42 - endpoints 43 - persistentvolumeclaims 44 - events 45 - configmaps 46 - secrets 47 verbs: 48 - "*" 49 - apiGroups: 50 - apps 51 resources: 52 - deployments 53 - daemonsets 54 - replicasets 55 - statefulsets 56 verbs: 57 - "*" 58 59 --- 60 61 kind: RoleBinding 62 apiVersion: rbac.authorization.k8s.io/v1beta1 63 metadata: 64 name: memcached-operator 65 subjects: 66 - kind: ServiceAccount 67 name: memcached-operator 68 roleRef: 69 kind: Role 70 name: memcached-operator 71 apiGroup: rbac.authorization.k8s.io 72 73 --- 74 75 apiVersion: apps/v1 76 kind: Deployment 77 metadata: 78 name: memcached-operator 79 spec: 80 replicas: 1 81 selector: 82 matchLabels: 83 name: memcached-operator 84 template: 85 metadata: 86 labels: 87 name: memcached-operator 88 spec: 89 serviceAccountName: memcached-operator 90 containers: 91 - name: memcached-operator 92 image: quay.io/coreos/operator-sdk-dev:test-framework-operator 93 command: 94 - memcached-operator 95 imagePullPolicy: Always 96 env: 97 - name: WATCH_NAMESPACE 98 valueFrom: 99 fieldRef: 100 fieldPath: metadata.namespace 101 - name: OPERATOR_NAME 102 value: "memcached-operator" 103 104 ` 105 106 func TestVerifyDeploymentImage(t *testing.T) { 107 if err := verifyDeploymentImage([]byte(memcachedNamespaceManExample), "quay.io/coreos/operator-sdk-dev:test-framework-operator"); err != nil { 108 t.Fatalf("Incorrectly reported an error: %v", err) 109 } 110 if err := verifyDeploymentImage([]byte(memcachedNamespaceManExample), "different-image-name"); err == nil { 111 t.Fatal("No error reported on an incorrect manifest") 112 } 113 }