github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v1beta12/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 v1beta12 18 19 import ( 20 "testing" 21 22 next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1beta13" 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/v1beta12 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/bazel 36 bazel: 37 target: //mytarget 38 googleCloudBuild: 39 projectId: test-project 40 test: 41 - image: gcr.io/k8s-skaffold/skaffold-example 42 structureTests: 43 - ./test/* 44 deploy: 45 kubectl: 46 manifests: 47 - k8s-* 48 profiles: 49 - name: test profile 50 build: 51 artifacts: 52 - image: gcr.io/k8s-skaffold/skaffold-example 53 kaniko: 54 buildContext: 55 gcsBucket: skaffold-kaniko 56 cache: {} 57 cluster: 58 pullSecretName: e2esecret 59 namespace: default 60 test: 61 - image: gcr.io/k8s-skaffold/skaffold-example 62 structureTests: 63 - ./test/* 64 deploy: 65 kubectl: 66 manifests: 67 - k8s-* 68 - name: test local 69 build: 70 artifacts: 71 - image: gcr.io/k8s-skaffold/skaffold-example 72 docker: 73 dockerfile: path/to/Dockerfile 74 local: 75 push: false 76 deploy: 77 kubectl: 78 manifests: 79 - k8s-* 80 ` 81 expected := `apiVersion: skaffold/v1beta13 82 kind: Config 83 build: 84 artifacts: 85 - image: gcr.io/k8s-skaffold/skaffold-example 86 docker: 87 dockerfile: path/to/Dockerfile 88 - image: gcr.io/k8s-skaffold/bazel 89 bazel: 90 target: //mytarget 91 googleCloudBuild: 92 projectId: test-project 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 kaniko: 107 buildContext: 108 gcsBucket: skaffold-kaniko 109 cache: {} 110 cluster: 111 pullSecretName: e2esecret 112 namespace: default 113 test: 114 - image: gcr.io/k8s-skaffold/skaffold-example 115 structureTests: 116 - ./test/* 117 deploy: 118 kubectl: 119 manifests: 120 - k8s-* 121 - name: test local 122 build: 123 artifacts: 124 - image: gcr.io/k8s-skaffold/skaffold-example 125 docker: 126 dockerfile: path/to/Dockerfile 127 local: 128 push: false 129 deploy: 130 kubectl: 131 manifests: 132 - k8s-* 133 ` 134 verifyUpgrade(t, yaml, expected) 135 } 136 137 func verifyUpgrade(t *testing.T, input, output string) { 138 config := NewSkaffoldConfig() 139 err := yaml.UnmarshalStrict([]byte(input), config) 140 testutil.CheckErrorAndDeepEqual(t, false, err, Version, config.GetVersion()) 141 142 upgraded, err := config.Upgrade() 143 testutil.CheckError(t, false, err) 144 145 expected := next.NewSkaffoldConfig() 146 err = yaml.UnmarshalStrict([]byte(output), expected) 147 148 testutil.CheckErrorAndDeepEqual(t, false, err, expected, upgraded) 149 }