github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/deploy/component/kubernetes/monitor_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/config" 24 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/label" 25 k8sstatus "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/status" 26 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" 27 "github.com/GoogleContainerTools/skaffold/testutil" 28 ) 29 30 type mockStatusConfig struct { 31 k8sstatus.Config 32 statusCheck *bool 33 } 34 35 func (m mockStatusConfig) StatusCheck() *bool { return m.statusCheck } 36 37 func (m mockStatusConfig) GetKubeContext() string { return "" } 38 39 func (m mockStatusConfig) StatusCheckDeadlineSeconds() int { return 0 } 40 41 func (m mockStatusConfig) Muted() config.Muted { return config.Muted{} } 42 43 func TestGetMonitor(t *testing.T) { 44 tests := []struct { 45 description string 46 statusCheck *bool 47 isNoop bool 48 }{ 49 { 50 description: "unspecified statusCheck parameter", 51 }, 52 { 53 description: "statusCheck parameter set to true", 54 statusCheck: util.BoolPtr(true), 55 }, 56 { 57 description: "statusCheck parameter set to false", 58 statusCheck: util.BoolPtr(false), 59 isNoop: true, 60 }, 61 } 62 63 for _, test := range tests { 64 testutil.Run(t, test.description, func(t *testutil.T) { 65 m := NewMonitor(mockStatusConfig{statusCheck: test.statusCheck}, test.description, label.NewLabeller(false, nil, ""), nil) 66 t.CheckDeepEqual(test.isNoop, reflect.Indirect(reflect.ValueOf(m)).Type() == reflect.TypeOf(k8sstatus.NoopMonitor{})) 67 }) 68 } 69 }