github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v2beta12/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 v2beta12 18 19 import ( 20 "testing" 21 22 next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v2beta13" 23 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml" 24 "github.com/GoogleContainerTools/skaffold/testutil" 25 ) 26 27 func TestUpgrade(t *testing.T) { 28 tests := []struct { 29 description string 30 yaml string 31 expected string 32 }{ 33 { 34 description: "no helm deploy", 35 yaml: `apiVersion: skaffold/v2beta12 36 kind: Config 37 build: 38 artifacts: 39 - image: gcr.io/k8s-skaffold/skaffold-example 40 docker: 41 dockerfile: path/to/Dockerfile 42 test: 43 - image: gcr.io/k8s-skaffold/skaffold-example 44 structureTests: 45 - ./test/* 46 deploy: 47 kubectl: 48 manifests: 49 - k8s-* 50 kustomize: 51 paths: 52 - kustomization-main`, 53 expected: `apiVersion: skaffold/v2beta13 54 kind: Config 55 build: 56 artifacts: 57 - image: gcr.io/k8s-skaffold/skaffold-example 58 docker: 59 dockerfile: path/to/Dockerfile 60 test: 61 - image: gcr.io/k8s-skaffold/skaffold-example 62 structureTests: 63 - ./test/* 64 deploy: 65 kubectl: 66 manifests: 67 - k8s-* 68 kustomize: 69 paths: 70 - kustomization-main`, 71 }, 72 { 73 description: "helm deploy with releases but no chart path set", 74 yaml: `apiVersion: skaffold/v2beta12 75 kind: Config 76 build: 77 artifacts: 78 - image: gcr.io/k8s-skaffold/skaffold-example 79 docker: 80 dockerfile: path/to/Dockerfile 81 deploy: 82 helm: 83 releases: 84 - name: skaffold`, 85 expected: `apiVersion: skaffold/v2beta13 86 kind: Config 87 build: 88 artifacts: 89 - image: gcr.io/k8s-skaffold/skaffold-example 90 docker: 91 dockerfile: path/to/Dockerfile 92 deploy: 93 helm: 94 releases: 95 - name: skaffold`, 96 }, 97 { 98 description: "helm deploy with multiple releases and mixed chart paths", 99 yaml: `apiVersion: skaffold/v2beta12 100 kind: Config 101 build: 102 artifacts: 103 - image: gcr.io/k8s-skaffold/skaffold-example 104 docker: 105 dockerfile: path/to/Dockerfile 106 deploy: 107 helm: 108 releases: 109 - name: foo1 110 chartPath: foo1/bar 111 - name: foo2 112 chartPath: foo2/bar 113 remote: true 114 - name: foo3 115 chartPath: foo3/bar 116 remote: false`, 117 expected: `apiVersion: skaffold/v2beta13 118 kind: Config 119 build: 120 artifacts: 121 - image: gcr.io/k8s-skaffold/skaffold-example 122 docker: 123 dockerfile: path/to/Dockerfile 124 deploy: 125 helm: 126 releases: 127 - name: foo1 128 chartPath: foo1/bar 129 - name: foo2 130 remoteChart: foo2/bar 131 - name: foo3 132 chartPath: foo3/bar`, 133 }, 134 } 135 for _, test := range tests { 136 testutil.Run(t, test.description, func(t *testutil.T) { 137 verifyUpgrade(t.T, test.yaml, test.expected) 138 }) 139 } 140 } 141 142 func verifyUpgrade(t *testing.T, input, output string) { 143 config := NewSkaffoldConfig() 144 err := yaml.UnmarshalStrict([]byte(input), config) 145 testutil.CheckErrorAndDeepEqual(t, false, err, Version, config.GetVersion()) 146 147 upgraded, err := config.Upgrade() 148 testutil.CheckError(t, false, err) 149 150 expected := next.NewSkaffoldConfig() 151 err = yaml.UnmarshalStrict([]byte(output), expected) 152 153 testutil.CheckErrorAndDeepEqual(t, false, err, expected, upgraded) 154 }