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