github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/kubernetes/generator/generate_test.go (about) 1 /* 2 Copyright 2020 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package generator 18 19 import ( 20 "testing" 21 22 "github.com/GoogleContainerTools/skaffold/testutil" 23 ) 24 25 func TestManifestGeneration(t *testing.T) { 26 tests := []struct { 27 description string 28 images []string 29 ports []int 30 expectedManifest string 31 }{ 32 { 33 description: "single image", 34 images: []string{"foo"}, 35 ports: []int{8080}, 36 expectedManifest: `apiVersion: v1 37 kind: Service 38 metadata: 39 name: foo 40 labels: 41 app: foo 42 spec: 43 ports: 44 - port: 8080 45 protocol: TCP 46 clusterIP: None 47 selector: 48 app: foo 49 --- 50 apiVersion: apps/v1 51 kind: Deployment 52 metadata: 53 name: foo 54 labels: 55 app: foo 56 spec: 57 replicas: 1 58 selector: 59 matchLabels: 60 app: foo 61 template: 62 metadata: 63 labels: 64 app: foo 65 spec: 66 containers: 67 - name: foo 68 image: foo 69 `, 70 }, 71 { 72 description: "single image, no port forward", 73 images: []string{"foo"}, 74 ports: []int{0}, 75 expectedManifest: `apiVersion: v1 76 kind: Service 77 metadata: 78 name: foo 79 labels: 80 app: foo 81 spec: 82 clusterIP: None 83 selector: 84 app: foo 85 --- 86 apiVersion: apps/v1 87 kind: Deployment 88 metadata: 89 name: foo 90 labels: 91 app: foo 92 spec: 93 replicas: 1 94 selector: 95 matchLabels: 96 app: foo 97 template: 98 metadata: 99 labels: 100 app: foo 101 spec: 102 containers: 103 - name: foo 104 image: foo 105 `, 106 }, 107 } 108 109 for _, test := range tests { 110 testutil.Run(t, test.description, func(t *testutil.T) { 111 for i, image := range test.images { 112 manifest, _, err := Generate(image, test.ports[i]) 113 114 t.CheckNoError(err) 115 t.CheckDeepEqual(test.expectedManifest, string(manifest)) 116 } 117 }) 118 } 119 }