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