github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v1alpha4/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 v1alpha4
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha5"
    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/v1alpha4
    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        artifacts:
    45        - image: gcr.io/k8s-skaffold/skaffold-example
    46      test:
    47       - image: gcr.io/k8s-skaffold/skaffold-example
    48         structureTests:
    49           - ./test/*
    50      deploy:
    51        kubectl:
    52          manifests:
    53          - k8s-*
    54  `
    55  	expected := `apiVersion: skaffold/v1alpha5
    56  kind: Config
    57  build:
    58    artifacts:
    59    - image: gcr.io/k8s-skaffold/skaffold-example
    60  test:
    61    - image: gcr.io/k8s-skaffold/skaffold-example
    62      structureTests:
    63       - ./test/*
    64  deploy:
    65    kubectl:
    66      manifests:
    67      - k8s-*
    68  profiles:
    69    - name: test profile
    70      build:
    71        artifacts:
    72        - image: gcr.io/k8s-skaffold/skaffold-example
    73      test:
    74       - image: gcr.io/k8s-skaffold/skaffold-example
    75         structureTests:
    76           - ./test/*
    77      deploy:
    78        kubectl:
    79          manifests:
    80          - k8s-*
    81  `
    82  	verifyUpgrade(t, yaml, expected)
    83  }
    84  
    85  func verifyUpgrade(t *testing.T, input, output string) {
    86  	config := NewSkaffoldConfig()
    87  	err := yaml.UnmarshalStrict([]byte(input), config)
    88  	testutil.CheckErrorAndDeepEqual(t, false, err, Version, config.GetVersion())
    89  
    90  	upgraded, err := config.Upgrade()
    91  	testutil.CheckError(t, false, err)
    92  
    93  	expected := v1alpha5.NewSkaffoldConfig()
    94  	err = yaml.UnmarshalStrict([]byte(output), expected)
    95  
    96  	testutil.CheckErrorAndDeepEqual(t, false, err, expected, upgraded)
    97  }