github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v2beta27/upgrade_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 v2beta27 18 19 import ( 20 "testing" 21 22 next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v2beta28" 23 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" 24 "github.com/GoogleContainerTools/skaffold/testutil" 25 ) 26 27 func TestUpgrade(t *testing.T) { 28 yaml := `apiVersion: skaffold/v2beta27 29 kind: Config 30 build: 31 artifacts: 32 - image: gcr.io/k8s-skaffold/skaffold-example 33 docker: 34 dockerfile: path/to/Dockerfile 35 secrets: 36 - id: id 37 src: /file.txt 38 - image: gcr.io/k8s-skaffold/bazel 39 bazel: 40 target: //mytarget 41 - image: gcr.io/k8s-skaffold/jib-maven 42 jib: 43 args: ['-v', '--activate-profiles', 'prof'] 44 project: dir 45 - image: gcr.io/k8s-skaffold/jib-gradle 46 jib: 47 args: ['-v'] 48 - image: gcr.io/k8s-skaffold/buildpacks 49 buildpacks: 50 builder: gcr.io/buildpacks/builder:v1 51 sync: 52 auto: true 53 - image: ko://github.com/GoogleContainerTools/skaffold/cmd/skaffold 54 ko: 55 platforms: ['linux/arm64', 'linux/amd64'] 56 googleCloudBuild: 57 projectId: test-project 58 test: 59 - image: gcr.io/k8s-skaffold/skaffold-example 60 structureTests: 61 - ./test/* 62 deploy: 63 kubectl: 64 manifests: 65 - k8s-* 66 kustomize: 67 paths: 68 - kustomization-main 69 portForward: 70 - resourceType: deployment 71 resourceName: leeroy-app 72 port: 8080 73 localPort: 9001 74 profiles: 75 - name: test profile 76 build: 77 artifacts: 78 - image: gcr.io/k8s-skaffold/skaffold-example 79 kaniko: 80 cache: {} 81 cluster: 82 pullSecretName: e2esecret 83 pullSecretPath: secret.json 84 namespace: default 85 test: 86 - image: gcr.io/k8s-skaffold/skaffold-example 87 structureTests: 88 - ./test/* 89 deploy: 90 kubectl: 91 manifests: 92 - k8s-* 93 kustomize: 94 paths: 95 - kustomization-test 96 - name: test local 97 build: 98 artifacts: 99 - image: gcr.io/k8s-skaffold/skaffold-example 100 docker: 101 dockerfile: path/to/Dockerfile 102 local: 103 push: false 104 deploy: 105 kubectl: 106 manifests: 107 - k8s-* 108 kustomize: {} 109 ` 110 expected := `apiVersion: skaffold/v2beta28 111 kind: Config 112 build: 113 artifacts: 114 - image: gcr.io/k8s-skaffold/skaffold-example 115 docker: 116 dockerfile: path/to/Dockerfile 117 secrets: 118 - id: id 119 src: /file.txt 120 - image: gcr.io/k8s-skaffold/bazel 121 bazel: 122 target: //mytarget 123 - image: gcr.io/k8s-skaffold/jib-maven 124 jib: 125 args: ['-v', '--activate-profiles', 'prof'] 126 project: dir 127 - image: gcr.io/k8s-skaffold/jib-gradle 128 jib: 129 args: ['-v'] 130 - image: gcr.io/k8s-skaffold/buildpacks 131 buildpacks: 132 builder: gcr.io/buildpacks/builder:v1 133 sync: 134 auto: true 135 - image: ko://github.com/GoogleContainerTools/skaffold/cmd/skaffold 136 ko: {} 137 platforms: ['linux/arm64', 'linux/amd64'] 138 googleCloudBuild: 139 projectId: test-project 140 test: 141 - image: gcr.io/k8s-skaffold/skaffold-example 142 structureTests: 143 - ./test/* 144 deploy: 145 kubectl: 146 manifests: 147 - k8s-* 148 kustomize: 149 paths: 150 - kustomization-main 151 portForward: 152 - resourceType: deployment 153 resourceName: leeroy-app 154 port: 8080 155 localPort: 9001 156 profiles: 157 - name: test profile 158 build: 159 artifacts: 160 - image: gcr.io/k8s-skaffold/skaffold-example 161 kaniko: 162 cache: {} 163 cluster: 164 pullSecretName: e2esecret 165 pullSecretPath: secret.json 166 namespace: default 167 test: 168 - image: gcr.io/k8s-skaffold/skaffold-example 169 structureTests: 170 - ./test/* 171 deploy: 172 kubectl: 173 manifests: 174 - k8s-* 175 kustomize: 176 paths: 177 - kustomization-test 178 - name: test local 179 build: 180 artifacts: 181 - image: gcr.io/k8s-skaffold/skaffold-example 182 docker: 183 dockerfile: path/to/Dockerfile 184 local: 185 push: false 186 deploy: 187 kubectl: 188 manifests: 189 - k8s-* 190 kustomize: {} 191 ` 192 verifyUpgrade(t, yaml, expected) 193 } 194 195 func verifyUpgrade(t *testing.T, input, output string) { 196 config := NewSkaffoldConfig() 197 err := yaml.UnmarshalStrict([]byte(input), config) 198 testutil.CheckErrorAndDeepEqual(t, false, err, Version, config.GetVersion()) 199 200 upgraded, err := config.Upgrade() 201 testutil.CheckError(t, false, err) 202 203 expected := next.NewSkaffoldConfig() 204 err = yaml.UnmarshalStrict([]byte(output), expected) 205 206 testutil.CheckErrorAndDeepEqual(t, false, err, expected, upgraded) 207 }