github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v1alpha5/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 v1alpha5 18 19 import ( 20 "testing" 21 22 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1beta1" 23 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" 24 "github.com/GoogleContainerTools/skaffold/testutil" 25 ) 26 27 func TestUpgrade_removeACR(t *testing.T) { 28 yaml := `apiVersion: skaffold/v1alpha5 29 kind: Config 30 build: 31 artifacts: 32 - image: myregistry.azurecr.io/skaffold-example 33 acr: {} 34 deploy: 35 kubectl: 36 manifests: 37 - k8s-* 38 ` 39 upgradeShouldFail(t, yaml) 40 } 41 42 func TestUpgrade_removeACRInProfiles(t *testing.T) { 43 yaml := `apiVersion: skaffold/v1alpha5 44 kind: Config 45 build: 46 artifacts: 47 - image: myregistry.azurecr.io/skaffold-example 48 deploy: 49 kubectl: 50 manifests: 51 - k8s-* 52 profiles: 53 - name: test profile 54 build: 55 acr: {} 56 ` 57 upgradeShouldFail(t, yaml) 58 } 59 60 func TestUpgrade(t *testing.T) { 61 yaml := `apiVersion: skaffold/v1alpha5 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 artifacts: 78 - image: gcr.io/k8s-skaffold/skaffold-example 79 test: 80 - image: gcr.io/k8s-skaffold/skaffold-example 81 structureTests: 82 - ./test/* 83 deploy: 84 kubectl: 85 manifests: 86 - k8s-* 87 ` 88 expected := `apiVersion: skaffold/v1beta1 89 kind: Config 90 build: 91 artifacts: 92 - image: gcr.io/k8s-skaffold/skaffold-example 93 test: 94 - image: gcr.io/k8s-skaffold/skaffold-example 95 structureTests: 96 - ./test/* 97 deploy: 98 kubectl: 99 manifests: 100 - k8s-* 101 profiles: 102 - name: test profile 103 build: 104 artifacts: 105 - image: gcr.io/k8s-skaffold/skaffold-example 106 test: 107 - image: gcr.io/k8s-skaffold/skaffold-example 108 structureTests: 109 - ./test/* 110 deploy: 111 kubectl: 112 manifests: 113 - k8s-* 114 ` 115 verifyUpgrade(t, yaml, expected) 116 } 117 118 func upgradeShouldFail(t *testing.T, input string) { 119 config := NewSkaffoldConfig() 120 err := yaml.UnmarshalStrict([]byte(input), config) 121 testutil.CheckErrorAndDeepEqual(t, false, err, Version, config.GetVersion()) 122 123 _, err = config.Upgrade() 124 testutil.CheckError(t, true, err) 125 } 126 127 func verifyUpgrade(t *testing.T, input, output string) { 128 config := NewSkaffoldConfig() 129 err := yaml.UnmarshalStrict([]byte(input), config) 130 testutil.CheckErrorAndDeepEqual(t, false, err, Version, config.GetVersion()) 131 132 upgraded, err := config.Upgrade() 133 testutil.CheckError(t, false, err) 134 135 expected := v1beta1.NewSkaffoldConfig() 136 err = yaml.UnmarshalStrict([]byte(output), expected) 137 138 testutil.CheckErrorAndDeepEqual(t, false, err, expected, upgraded) 139 }