|
| 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 cmd |
| 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 | + ports: |
| 94 | + - containerPort: 60000 |
| 95 | + name: metrics |
| 96 | + command: |
| 97 | + - memcached-operator |
| 98 | + imagePullPolicy: Always |
| 99 | + env: |
| 100 | + - name: WATCH_NAMESPACE |
| 101 | + valueFrom: |
| 102 | + fieldRef: |
| 103 | + fieldPath: metadata.namespace |
| 104 | + - name: OPERATOR_NAME |
| 105 | + value: "memcached-operator" |
| 106 | +
|
| 107 | +` |
| 108 | + |
| 109 | +func TestVerifyDeploymentImage(t *testing.T) { |
| 110 | + if err := verifyDeploymentImage([]byte(memcachedNamespaceManExample), "quay.io/coreos/operator-sdk-dev:test-framework-operator"); err != nil { |
| 111 | + t.Fatalf("verifyDeploymentImage incorrectly reported an error: %v", err) |
| 112 | + } |
| 113 | + if err := verifyDeploymentImage([]byte(memcachedNamespaceManExample), "different-image-name"); err == nil { |
| 114 | + t.Fatal("verifyDeploymentImage did not report an error on an incorrect manifest") |
| 115 | + } |
| 116 | +} |
0 commit comments