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