github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v2beta5/upgrade_test.go (about)

     1  /*
     2  Copyright 2020 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 v2beta5
    18  
    19  import (
    20  	"testing"
    21  
    22  	yaml "gopkg.in/yaml.v2"
    23  
    24  	next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v2beta6"
    25  	"github.com/GoogleContainerTools/skaffold/testutil"
    26  )
    27  
    28  func TestUpgrade(t *testing.T) {
    29  	yaml := `apiVersion: skaffold/v2beta5
    30  kind: Config
    31  build:
    32    artifacts:
    33    - image: gcr.io/k8s-skaffold/skaffold-example
    34      docker:
    35        dockerfile: path/to/Dockerfile
    36    - image: gcr.io/k8s-skaffold/bazel
    37      bazel:
    38        target: //mytarget
    39    - image: gcr.io/k8s-skaffold/jib-maven
    40      jib:
    41        args: ['-v', '--activate-profiles', 'prof']
    42        project: dir
    43    - image: gcr.io/k8s-skaffold/jib-gradle
    44      jib:
    45        args: ['-v']
    46    - image: gcr.io/k8s-skaffold/buildpacks
    47      buildpacks:
    48        builder: gcr.io/buildpacks/builder:v1
    49    googleCloudBuild:
    50      projectId: test-project
    51  test:
    52    - image: gcr.io/k8s-skaffold/skaffold-example
    53      structureTests:
    54       - ./test/*
    55  deploy:
    56    kubectl:
    57      manifests:
    58      - k8s-*
    59    kustomize:
    60      paths:
    61      - kustomization-main
    62  profiles:
    63    - name: test profile
    64      build:
    65        artifacts:
    66        - image: gcr.io/k8s-skaffold/skaffold-example
    67          kaniko:
    68            cache: {}
    69        cluster:
    70          pullSecretName: e2esecret
    71          pullSecretPath: secret.json
    72          namespace: default
    73      test:
    74       - image: gcr.io/k8s-skaffold/skaffold-example
    75         structureTests:
    76           - ./test/*
    77      deploy:
    78        kubectl:
    79          manifests:
    80          - k8s-*
    81        kustomize:
    82          paths:
    83          - kustomization-test
    84    - name: test local
    85      build:
    86        artifacts:
    87        - image: gcr.io/k8s-skaffold/skaffold-example
    88          docker:
    89            dockerfile: path/to/Dockerfile
    90        local:
    91          push: false
    92      deploy:
    93        kubectl:
    94          manifests:
    95          - k8s-*
    96        kustomize: {}
    97  `
    98  	expected := `apiVersion: skaffold/v2beta6
    99  kind: Config
   100  build:
   101    artifacts:
   102    - image: gcr.io/k8s-skaffold/skaffold-example
   103      docker:
   104        dockerfile: path/to/Dockerfile
   105    - image: gcr.io/k8s-skaffold/bazel
   106      bazel:
   107        target: //mytarget
   108    - image: gcr.io/k8s-skaffold/jib-maven
   109      jib:
   110        args: ['-v', '--activate-profiles', 'prof']
   111        project: dir
   112    - image: gcr.io/k8s-skaffold/jib-gradle
   113      jib:
   114        args: ['-v']
   115    - image: gcr.io/k8s-skaffold/buildpacks
   116      buildpacks:
   117        builder: gcr.io/buildpacks/builder:v1
   118    googleCloudBuild:
   119      projectId: test-project
   120  test:
   121    - image: gcr.io/k8s-skaffold/skaffold-example
   122      structureTests:
   123       - ./test/*
   124  deploy:
   125    kubectl:
   126      manifests:
   127      - k8s-*
   128    kustomize:
   129      paths:
   130      - kustomization-main
   131  profiles:
   132    - name: test profile
   133      build:
   134        artifacts:
   135        - image: gcr.io/k8s-skaffold/skaffold-example
   136          kaniko:
   137            cache: {}
   138        cluster:
   139          pullSecretName: e2esecret
   140          pullSecretPath: secret.json
   141          namespace: default
   142      test:
   143       - image: gcr.io/k8s-skaffold/skaffold-example
   144         structureTests:
   145           - ./test/*
   146      deploy:
   147        kubectl:
   148          manifests:
   149          - k8s-*
   150        kustomize:
   151          paths:
   152          - kustomization-test
   153    - name: test local
   154      build:
   155        artifacts:
   156        - image: gcr.io/k8s-skaffold/skaffold-example
   157          docker:
   158            dockerfile: path/to/Dockerfile
   159        local:
   160          push: false
   161      deploy:
   162        kubectl:
   163          manifests:
   164          - k8s-*
   165        kustomize: {}
   166  `
   167  	verifyUpgrade(t, yaml, expected)
   168  }
   169  
   170  func verifyUpgrade(t *testing.T, input, output string) {
   171  	config := NewSkaffoldConfig()
   172  	err := yaml.UnmarshalStrict([]byte(input), config)
   173  	testutil.CheckErrorAndDeepEqual(t, false, err, Version, config.GetVersion())
   174  
   175  	upgraded, err := config.Upgrade()
   176  	testutil.CheckError(t, false, err)
   177  
   178  	expected := next.NewSkaffoldConfig()
   179  	err = yaml.UnmarshalStrict([]byte(output), expected)
   180  
   181  	testutil.CheckErrorAndDeepEqual(t, false, err, expected, upgraded)
   182  }