github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v1beta1/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 v1beta1 18 19 import ( 20 "testing" 21 22 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1beta2" 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/v1beta1 29 kind: Config 30 build: 31 artifacts: 32 - image: gcr.io/k8s-skaffold/skaffold-example 33 test: 34 - image: gcr.io/k8s-skaffold/skaffold-example 35 structureTests: 36 - ./test/* 37 deploy: 38 kubectl: 39 manifests: 40 - k8s-* 41 profiles: 42 - name: test profile 43 build: 44 kaniko: 45 buildContext: 46 gcsBucket: skaffold-kaniko 47 pullSecretName: e2esecret 48 namespace: default 49 cache: {} 50 artifacts: 51 - image: gcr.io/k8s-skaffold/skaffold-example 52 test: 53 - image: gcr.io/k8s-skaffold/skaffold-example 54 structureTests: 55 - ./test/* 56 deploy: 57 kubectl: 58 manifests: 59 - k8s-* 60 ` 61 expected := `apiVersion: skaffold/v1beta2 62 kind: Config 63 build: 64 artifacts: 65 - image: gcr.io/k8s-skaffold/skaffold-example 66 test: 67 - image: gcr.io/k8s-skaffold/skaffold-example 68 structureTests: 69 - ./test/* 70 deploy: 71 kubectl: 72 manifests: 73 - k8s-* 74 profiles: 75 - name: test profile 76 build: 77 kaniko: 78 buildContext: 79 gcsBucket: skaffold-kaniko 80 pullSecretName: e2esecret 81 namespace: default 82 cache: {} 83 # default should be no flags at upgrade 84 flags: 85 artifacts: 86 - image: gcr.io/k8s-skaffold/skaffold-example 87 test: 88 - image: gcr.io/k8s-skaffold/skaffold-example 89 structureTests: 90 - ./test/* 91 deploy: 92 kubectl: 93 manifests: 94 - k8s-* 95 ` 96 verifyUpgrade(t, yaml, expected) 97 } 98 99 func verifyUpgrade(t *testing.T, input, output string) { 100 config := NewSkaffoldConfig() 101 err := yaml.UnmarshalStrict([]byte(input), config) 102 testutil.CheckErrorAndDeepEqual(t, false, err, Version, config.GetVersion()) 103 104 upgraded, err := config.Upgrade() 105 testutil.CheckError(t, false, err) 106 107 expected := v1beta2.NewSkaffoldConfig() 108 err = yaml.UnmarshalStrict([]byte(output), expected) 109 110 testutil.CheckErrorAndDeepEqual(t, false, err, expected, upgraded) 111 }