github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v2alpha2/upgrade_test.go (about) 1 /* 2 Copyright 2019 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 v2alpha2 18 19 import ( 20 "testing" 21 22 next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v2alpha3" 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/v2alpha2 29 kind: Config 30 build: 31 artifacts: 32 - image: gcr.io/k8s-skaffold/skaffold-example 33 docker: 34 dockerfile: path/to/Dockerfile 35 - image: gcr.io/k8s-skaffold/bazel 36 bazel: 37 target: //mytarget 38 - image: gcr.io/k8s-skaffold/jib-maven 39 jib: 40 args: ['-v', '--activate-profiles', 'prof'] 41 project: dir 42 - image: gcr.io/k8s-skaffold/jib-gradle 43 jib: 44 args: ['-v'] 45 googleCloudBuild: 46 projectId: test-project 47 test: 48 - image: gcr.io/k8s-skaffold/skaffold-example 49 structureTests: 50 - ./test/* 51 deploy: 52 kubectl: 53 manifests: 54 - k8s-* 55 kustomize: 56 path: kustomization-main 57 profiles: 58 - name: test profile 59 build: 60 artifacts: 61 - image: gcr.io/k8s-skaffold/skaffold-example 62 kaniko: 63 cache: {} 64 cluster: 65 pullSecretName: e2esecret 66 namespace: default 67 test: 68 - image: gcr.io/k8s-skaffold/skaffold-example 69 structureTests: 70 - ./test/* 71 deploy: 72 kubectl: 73 manifests: 74 - k8s-* 75 kustomize: 76 path: kustomization-test 77 - name: test local 78 build: 79 artifacts: 80 - image: gcr.io/k8s-skaffold/skaffold-example 81 docker: 82 dockerfile: path/to/Dockerfile 83 local: 84 push: false 85 deploy: 86 kubectl: 87 manifests: 88 - k8s-* 89 kustomize: {} 90 ` 91 expected := `apiVersion: skaffold/v2alpha3 92 kind: Config 93 build: 94 artifacts: 95 - image: gcr.io/k8s-skaffold/skaffold-example 96 docker: 97 dockerfile: path/to/Dockerfile 98 - image: gcr.io/k8s-skaffold/bazel 99 bazel: 100 target: //mytarget 101 - image: gcr.io/k8s-skaffold/jib-maven 102 jib: 103 args: ['-v', '--activate-profiles', 'prof'] 104 project: dir 105 - image: gcr.io/k8s-skaffold/jib-gradle 106 jib: 107 args: ['-v'] 108 googleCloudBuild: 109 projectId: test-project 110 test: 111 - image: gcr.io/k8s-skaffold/skaffold-example 112 structureTests: 113 - ./test/* 114 deploy: 115 kubectl: 116 manifests: 117 - k8s-* 118 kustomize: 119 paths: 120 - kustomization-main 121 profiles: 122 - name: test profile 123 build: 124 artifacts: 125 - image: gcr.io/k8s-skaffold/skaffold-example 126 kaniko: 127 cache: {} 128 cluster: 129 pullSecretName: e2esecret 130 namespace: default 131 test: 132 - image: gcr.io/k8s-skaffold/skaffold-example 133 structureTests: 134 - ./test/* 135 deploy: 136 kubectl: 137 manifests: 138 - k8s-* 139 kustomize: 140 paths: 141 - kustomization-test 142 - name: test local 143 build: 144 artifacts: 145 - image: gcr.io/k8s-skaffold/skaffold-example 146 docker: 147 dockerfile: path/to/Dockerfile 148 local: 149 push: false 150 deploy: 151 kubectl: 152 manifests: 153 - k8s-* 154 kustomize: {} 155 ` 156 verifyUpgrade(t, yaml, expected) 157 } 158 159 func verifyUpgrade(t *testing.T, input, output string) { 160 config := NewSkaffoldConfig() 161 err := yaml.UnmarshalStrict([]byte(input), config) 162 testutil.CheckErrorAndDeepEqual(t, false, err, Version, config.GetVersion()) 163 164 upgraded, err := config.Upgrade() 165 testutil.CheckError(t, false, err) 166 167 expected := next.NewSkaffoldConfig() 168 err = yaml.UnmarshalStrict([]byte(output), expected) 169 170 testutil.CheckErrorAndDeepEqual(t, false, err, expected, upgraded) 171 }