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