github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/initializer/util/util_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 util 18 19 import ( 20 "testing" 21 22 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" 23 "github.com/GoogleContainerTools/skaffold/testutil" 24 ) 25 26 func TestListBuilders(t *testing.T) { 27 tests := []struct { 28 description string 29 build *latest.BuildConfig 30 expected []string 31 }{ 32 { 33 description: "nil config", 34 build: nil, 35 expected: []string{}, 36 }, 37 { 38 description: "multiple same builder config", 39 build: &latest.BuildConfig{ 40 Artifacts: []*latest.Artifact{ 41 {ImageName: "img1", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, 42 {ImageName: "img2", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, 43 }, 44 }, 45 expected: []string{"docker"}, 46 }, 47 { 48 description: "different builders config", 49 build: &latest.BuildConfig{ 50 Artifacts: []*latest.Artifact{ 51 {ImageName: "img1", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, 52 {ImageName: "img2", ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}}, 53 }, 54 }, 55 expected: []string{"docker", "jib"}, 56 }, 57 } 58 for _, test := range tests { 59 testutil.Run(t, test.description, func(t *testutil.T) { 60 got := ListBuilders(test.build) 61 t.CheckDeepEqual(test.expected, got) 62 }) 63 } 64 } 65 66 func TestListDeployers(t *testing.T) { 67 tests := []struct { 68 description string 69 deploy *latest.DeployConfig 70 expected []string 71 }{ 72 { 73 description: "nil config", 74 deploy: nil, 75 expected: []string{}, 76 }, 77 { 78 description: "single deployer config", 79 deploy: &latest.DeployConfig{ 80 DeployType: latest.DeployType{ 81 KubectlDeploy: &latest.KubectlDeploy{}, 82 }, 83 }, 84 expected: []string{"kubectl"}, 85 }, 86 { 87 description: "multiple deployers config", 88 deploy: &latest.DeployConfig{ 89 DeployType: latest.DeployType{ 90 HelmDeploy: &latest.HelmDeploy{}, 91 KubectlDeploy: &latest.KubectlDeploy{}, 92 }, 93 }, 94 expected: []string{"helm", "kubectl"}, 95 }, 96 } 97 for _, test := range tests { 98 testutil.Run(t, test.description, func(t *testutil.T) { 99 got := ListDeployers(test.deploy) 100 t.CheckDeepEqual(test.expected, got) 101 }) 102 } 103 }