github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v1alpha2/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 v1alpha2
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha3"
    23  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml"
    24  	"github.com/GoogleContainerTools/skaffold/testutil"
    25  )
    26  
    27  func TestUpgrade_helmReleaseValuesFile(t *testing.T) {
    28  	yaml := `apiVersion: skaffold/v1alpha2
    29  kind: Config
    30  deploy:
    31    helm:
    32      releases:
    33      - name: test release
    34        valuesFilePath: values.yaml
    35  `
    36  	expected := `apiVersion: skaffold/v1alpha3
    37  kind: Config
    38  deploy:
    39    helm:
    40      releases:
    41      - name: test release
    42        valuesFiles:
    43        - values.yaml
    44  `
    45  	verifyUpgrade(t, yaml, expected)
    46  }
    47  
    48  func TestUpgrade_helmReleaseValuesFileWithProfile(t *testing.T) {
    49  	yaml := `apiVersion: skaffold/v1alpha2
    50  kind: Config
    51  profiles:
    52  - name: test
    53    deploy:
    54      helm:
    55        releases:
    56        - name: test
    57          valuesFilePath: values.yaml
    58  `
    59  	expected := `apiVersion: skaffold/v1alpha3
    60  kind: Config
    61  profiles:
    62  - name: test
    63    deploy:
    64      helm:
    65        releases:
    66        - name: test
    67          valuesFiles:
    68          - values.yaml
    69  `
    70  	verifyUpgrade(t, yaml, expected)
    71  }
    72  
    73  func TestUpgrade_kanikoWithProfile(t *testing.T) {
    74  	yaml := `apiVersion: skaffold/v1alpha2
    75  kind: Config
    76  build:
    77    artifacts:
    78    - imageName: gcr.io/k8s-skaffold/skaffold-example
    79    kaniko:
    80      gcsBucket: k8s-skaffold
    81      pullSecret: /a/secret/path/kaniko.json
    82  deploy:
    83    kubectl:
    84      manifests:
    85      - k8s-*
    86  profiles:
    87    - name: test profile
    88      build:
    89        artifacts:
    90        - imageName: gcr.io/k8s-skaffold/skaffold-example
    91      deploy:
    92        kubectl:
    93          manifests:
    94          - k8s-*
    95  `
    96  	expected := `apiVersion: skaffold/v1alpha3
    97  kind: Config
    98  build:
    99    artifacts:
   100    - imageName: gcr.io/k8s-skaffold/skaffold-example
   101    kaniko:
   102      buildContext:
   103        gcsBucket: k8s-skaffold
   104      pullSecret: /a/secret/path/kaniko.json
   105  deploy:
   106    kubectl:
   107      manifests:
   108      - k8s-*
   109  profiles:
   110    - name: test profile
   111      build:
   112        artifacts:
   113        - imageName: gcr.io/k8s-skaffold/skaffold-example
   114      deploy:
   115        kubectl:
   116          manifests:
   117          - k8s-*
   118  `
   119  	verifyUpgrade(t, yaml, expected)
   120  }
   121  
   122  func TestUpgrade_helmReleaseOverrides(t *testing.T) {
   123  	yaml := `apiVersion: skaffold/v1alpha2
   124  kind: Config
   125  deploy:
   126    helm:
   127      releases:
   128      - name: test release
   129        overrides:
   130          global:
   131            localstack:
   132              enabled: true
   133  `
   134  	expected := `apiVersion: skaffold/v1alpha3
   135  kind: Config
   136  deploy:
   137    helm:
   138      releases:
   139      - name: test release
   140        overrides:
   141          global:
   142            localstack:
   143              enabled: true
   144  `
   145  	verifyUpgrade(t, yaml, expected)
   146  }
   147  
   148  func verifyUpgrade(t *testing.T, input, output string) {
   149  	config := NewSkaffoldConfig()
   150  	err := yaml.UnmarshalStrict([]byte(input), config)
   151  	testutil.CheckErrorAndDeepEqual(t, false, err, Version, config.GetVersion())
   152  
   153  	upgraded, err := config.Upgrade()
   154  	testutil.CheckError(t, false, err)
   155  
   156  	expected := v1alpha3.NewSkaffoldConfig()
   157  	err = yaml.UnmarshalStrict([]byte(output), expected)
   158  
   159  	testutil.CheckErrorAndDeepEqual(t, false, err, expected, upgraded)
   160  }