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