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