github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/deploy/component/kubernetes/accessor_test.go (about) 1 /* 2 Copyright 2021 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 kubernetes 18 19 import ( 20 "reflect" 21 "testing" 22 23 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/access" 24 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" 25 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/label" 26 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl" 27 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/portforward" 28 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" 29 "github.com/GoogleContainerTools/skaffold/testutil" 30 ) 31 32 type mockAccessConfig struct { 33 portforward.Config 34 opts config.PortForwardOptions 35 } 36 37 func (m mockAccessConfig) Mode() config.RunMode { return "" } 38 39 func (m mockAccessConfig) PortForwardOptions() config.PortForwardOptions { return m.opts } 40 41 func (m mockAccessConfig) PortForwardResources() []*latest.PortForwardResource { return nil } 42 43 func TestGetAccessor(t *testing.T) { 44 tests := []struct { 45 description string 46 enabled bool 47 isNoop bool 48 }{ 49 { 50 description: "unspecified parameter defaults to disabled", 51 isNoop: true, 52 }, 53 { 54 description: "portForwardEnabled parameter set to true", 55 enabled: true, 56 }, 57 { 58 description: "portForwardEnabled parameter set to false", 59 isNoop: true, 60 }, 61 } 62 63 for _, test := range tests { 64 testutil.Run(t, test.description, func(t *testutil.T) { 65 opts := config.PortForwardOptions{} 66 if test.enabled { 67 opts.Append("1") // default enabled mode 68 } 69 a := NewAccessor(mockAccessConfig{opts: opts}, test.description, &kubectl.CLI{}, nil, label.NewLabeller(false, nil, ""), nil) 70 t.CheckDeepEqual(test.isNoop, reflect.Indirect(reflect.ValueOf(a)).Type() == reflect.TypeOf(access.NoopAccessor{})) 71 }) 72 } 73 }