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