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