github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/warnings/warnings.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 warnings 18 19 import ( 20 "context" 21 "fmt" 22 "sort" 23 24 olog "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log" 25 ) 26 27 // Warner prints warnings 28 type Warner func(format string, args ...interface{}) 29 30 // Printf can be overridden for testing 31 var Printf = olog.Entry(context.TODO()).Warnf 32 33 // Collect is used for testing to collect warnings 34 // instead of printing them 35 type Collect struct { 36 Warnings []string 37 } 38 39 // Warnf collects all the warnings for unit tests 40 func (l *Collect) Warnf(format string, args ...interface{}) { 41 l.Warnings = append(l.Warnings, fmt.Sprintf(format, args...)) 42 sort.Strings(l.Warnings) 43 }