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