github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v2beta3/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 v2beta3 18 19 import ( 20 "testing" 21 22 next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v2beta4" 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/v2beta3 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/v2beta4 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 values set", 74 yaml: `apiVersion: skaffold/v2beta3 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 chartPath: dummy`, 86 expected: `apiVersion: skaffold/v2beta4 87 kind: Config 88 build: 89 artifacts: 90 - image: gcr.io/k8s-skaffold/skaffold-example 91 docker: 92 dockerfile: path/to/Dockerfile 93 deploy: 94 helm: 95 releases: 96 - name: skaffold 97 chartPath: dummy`, 98 }, 99 { 100 description: "helm deploy with multiple releases values set", 101 yaml: `apiVersion: skaffold/v2beta3 102 kind: Config 103 build: 104 artifacts: 105 - image: gcr.io/k8s-skaffold/skaffold-example 106 docker: 107 dockerfile: path/to/Dockerfile 108 deploy: 109 helm: 110 releases: 111 - name: foo 112 values: 113 image1: foo 114 image2: bar 115 - name: bat 116 values: 117 image1: bat`, 118 expected: `apiVersion: skaffold/v2beta4 119 kind: Config 120 build: 121 artifacts: 122 - image: gcr.io/k8s-skaffold/skaffold-example 123 docker: 124 dockerfile: path/to/Dockerfile 125 deploy: 126 helm: 127 releases: 128 - name: foo 129 artifactOverrides: 130 image1: foo 131 image2: bar 132 - name: bat 133 artifactOverrides: 134 image1: bat`, 135 }, 136 } 137 for _, test := range tests { 138 testutil.Run(t, test.description, func(t *testutil.T) { 139 verifyUpgrade(t, test.yaml, test.expected) 140 }) 141 } 142 } 143 144 func verifyUpgrade(t *testutil.T, input, output string) { 145 config := NewSkaffoldConfig() 146 147 err := yaml.UnmarshalStrict([]byte(input), config) 148 t.CheckNoError(err) 149 t.CheckDeepEqual(Version, config.GetVersion()) 150 151 upgraded, err := config.Upgrade() 152 t.CheckNoError(err) 153 154 expected := next.NewSkaffoldConfig() 155 err = yaml.UnmarshalStrict([]byte(output), expected) 156 157 t.CheckNoError(err) 158 t.CheckDeepEqual(expected, upgraded) 159 }