github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/util/upgrade_pipelines_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 util
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/GoogleContainerTools/skaffold/testutil"
    23  )
    24  
    25  type testConfig struct {
    26  	Pipeline testPipeline
    27  	Profiles []testConfig
    28  }
    29  
    30  type testPipeline struct {
    31  	name string
    32  }
    33  
    34  func TestUpgradePipelines(t *testing.T) {
    35  	from := testConfig{
    36  		Pipeline: testPipeline{name: "main"},
    37  		Profiles: []testConfig{
    38  			{Pipeline: testPipeline{name: "profile-0"}},
    39  			{Pipeline: testPipeline{name: "profile-1"}},
    40  		},
    41  	}
    42  	to := testConfig{
    43  		Profiles: []testConfig{{}, {}},
    44  	}
    45  
    46  	testUpgrade := func(o, n interface{}) error {
    47  		src := o.(*testPipeline)
    48  		dest := n.(*testPipeline)
    49  
    50  		dest.name = src.name + "-upgraded"
    51  		return nil
    52  	}
    53  
    54  	err := UpgradePipelines(&from, &to, testUpgrade)
    55  	testutil.CheckError(t, false, err)
    56  
    57  	if to.Pipeline.name != "main-upgraded" {
    58  		t.Error("expected main pipeline to be upgraded")
    59  	}
    60  	if to.Profiles[0].Pipeline.name != "profile-0-upgraded" {
    61  		t.Error("expected profile-0 to be upgraded")
    62  	}
    63  	if to.Profiles[1].Pipeline.name != "profile-1-upgraded" {
    64  		t.Error("expected profile-1 to be upgraded")
    65  	}
    66  }