github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v1alpha3/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 v1alpha3
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha4"
    23  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/yaml"
    24  	"github.com/GoogleContainerTools/skaffold/testutil"
    25  )
    26  
    27  func TestUpgrade_imageName(t *testing.T) {
    28  	yaml := `apiVersion: skaffold/v1alpha3
    29  kind: Config
    30  build:
    31    artifacts:
    32    - imageName: gcr.io/k8s-skaffold/skaffold-example
    33  deploy:
    34    kubectl:
    35      manifests:
    36      - k8s-*
    37  profiles:
    38    - name: test profile
    39      build:
    40        artifacts:
    41        - imageName: gcr.io/k8s-skaffold/skaffold-example
    42      deploy:
    43        kubectl:
    44          manifests:
    45          - k8s-*
    46  `
    47  	expected := `apiVersion: skaffold/v1alpha4
    48  kind: Config
    49  build:
    50    artifacts:
    51    - image: gcr.io/k8s-skaffold/skaffold-example
    52  deploy:
    53    kubectl:
    54      manifests:
    55      - k8s-*
    56  profiles:
    57    - name: test profile
    58      build:
    59        artifacts:
    60        - image: gcr.io/k8s-skaffold/skaffold-example
    61      deploy:
    62        kubectl:
    63          manifests:
    64          - k8s-*
    65  `
    66  	verifyUpgrade(t, yaml, expected)
    67  }
    68  
    69  func TestUpgrade_skipPush(t *testing.T) {
    70  	yaml := `apiVersion: skaffold/v1alpha3
    71  kind: Config
    72  build:
    73    local:	
    74      skipPush: false
    75  profiles:
    76    - name: testEnv1
    77      build:
    78        local:
    79          skipPush: true
    80    - name: testEnv2
    81      build:
    82        local:
    83          skipPush: false
    84  `
    85  	expected := `apiVersion: skaffold/v1alpha4
    86  kind: Config
    87  build:
    88    local:	
    89      push: true
    90  profiles:
    91    - name: testEnv1
    92      build:
    93        local:
    94          push: false
    95    - name: testEnv2
    96      build:
    97        local:
    98          push: true
    99  `
   100  	verifyUpgrade(t, yaml, expected)
   101  }
   102  
   103  func verifyUpgrade(t *testing.T, input, output string) {
   104  	config := NewSkaffoldConfig()
   105  	err := yaml.UnmarshalStrict([]byte(input), config)
   106  	testutil.CheckErrorAndDeepEqual(t, false, err, Version, config.GetVersion())
   107  
   108  	upgraded, err := config.Upgrade()
   109  	testutil.CheckError(t, false, err)
   110  
   111  	expected := v1alpha4.NewSkaffoldConfig()
   112  	err = yaml.UnmarshalStrict([]byte(output), expected)
   113  
   114  	testutil.CheckErrorAndDeepEqual(t, false, err, expected, upgraded)
   115  }