github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v1beta13/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 v1beta13
    18  
    19  import (
    20  	"testing"
    21  
    22  	next "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1beta14"
    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/v1beta13
    29  kind: Config
    30  build:
    31    artifacts:
    32    - image: gcr.io/k8s-skaffold/skaffold-example
    33      docker:
    34        dockerfile: path/to/Dockerfile
    35    - image: gcr.io/k8s-skaffold/bazel
    36      bazel:
    37        target: //mytarget
    38    - image: gcr.io/k8s-skaffold/jib-maven
    39      jibMaven:
    40        args: ['-v']
    41        profile: prof
    42        module: dir
    43    - image: gcr.io/k8s-skaffold/jib-gradle
    44      jibGradle:
    45        args: ['-v']
    46    googleCloudBuild:
    47      projectId: test-project
    48  test:
    49    - image: gcr.io/k8s-skaffold/skaffold-example
    50      structureTests:
    51       - ./test/*
    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          kaniko:
    62            buildContext:
    63              gcsBucket: skaffold-kaniko
    64            cache: {}
    65        cluster:
    66          pullSecretName: e2esecret
    67          namespace: default
    68      test:
    69       - image: gcr.io/k8s-skaffold/skaffold-example
    70         structureTests:
    71           - ./test/*
    72      deploy:
    73        kubectl:
    74          manifests:
    75          - k8s-*
    76    - name: test local
    77      build:
    78        artifacts:
    79        - image: gcr.io/k8s-skaffold/skaffold-example
    80          docker:
    81            dockerfile: path/to/Dockerfile
    82        local:
    83          push: false
    84      deploy:
    85        kubectl:
    86          manifests:
    87          - k8s-*
    88  `
    89  	expected := `apiVersion: skaffold/v1beta14
    90  kind: Config
    91  build:
    92    artifacts:
    93    - image: gcr.io/k8s-skaffold/skaffold-example
    94      docker:
    95        dockerfile: path/to/Dockerfile
    96    - image: gcr.io/k8s-skaffold/bazel
    97      bazel:
    98        target: //mytarget
    99    - image: gcr.io/k8s-skaffold/jib-maven
   100      jib:
   101        args: ['-v', '--activate-profiles', 'prof']
   102        project: dir
   103        type: maven
   104    - image: gcr.io/k8s-skaffold/jib-gradle
   105      jib:
   106        args: ['-v']
   107        type: gradle
   108    googleCloudBuild:
   109      projectId: test-project
   110  test:
   111    - image: gcr.io/k8s-skaffold/skaffold-example
   112      structureTests:
   113       - ./test/*
   114  deploy:
   115    kubectl:
   116      manifests:
   117      - k8s-*
   118  profiles:
   119    - name: test profile
   120      build:
   121        artifacts:
   122        - image: gcr.io/k8s-skaffold/skaffold-example
   123          kaniko:
   124            buildContext:
   125              gcsBucket: skaffold-kaniko
   126            cache: {}
   127        cluster:
   128          pullSecretName: e2esecret
   129          namespace: default
   130      test:
   131       - image: gcr.io/k8s-skaffold/skaffold-example
   132         structureTests:
   133           - ./test/*
   134      deploy:
   135        kubectl:
   136          manifests:
   137          - k8s-*
   138    - name: test local
   139      build:
   140        artifacts:
   141        - image: gcr.io/k8s-skaffold/skaffold-example
   142          docker:
   143            dockerfile: path/to/Dockerfile
   144        local:
   145          push: false
   146      deploy:
   147        kubectl:
   148          manifests:
   149          - k8s-*
   150  `
   151  	verifyUpgrade(t, yaml, expected)
   152  }
   153  
   154  func verifyUpgrade(t *testing.T, input, output string) {
   155  	config := NewSkaffoldConfig()
   156  	err := yaml.UnmarshalStrict([]byte(input), config)
   157  	testutil.CheckErrorAndDeepEqual(t, false, err, Version, config.GetVersion())
   158  
   159  	upgraded, err := config.Upgrade()
   160  	testutil.CheckError(t, false, err)
   161  
   162  	expected := next.NewSkaffoldConfig()
   163  	err = yaml.UnmarshalStrict([]byte(output), expected)
   164  
   165  	testutil.CheckErrorAndDeepEqual(t, false, err, expected, upgraded)
   166  }