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