sigs.k8s.io/cluster-api-provider-azure@v1.14.3/pkg/cloudtest/cloudtest.go (about) 1 /* 2 Copyright 2019 The Kubernetes 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 cloudtest 18 19 import ( 20 "encoding/json" 21 "testing" 22 23 "github.com/go-logr/logr" 24 "k8s.io/apimachinery/pkg/runtime" 25 ) 26 27 // RuntimeRawExtension takes anything and turns it into a *runtime.RawExtension. 28 // This is helpful for creating clusterv1.Cluster/Machine objects that need 29 // a specific AzureClusterProviderSpec or Status. 30 func RuntimeRawExtension(t *testing.T, p interface{}) *runtime.RawExtension { 31 t.Helper() 32 out, err := json.Marshal(p) 33 if err != nil { 34 t.Fatal(err) 35 } 36 return &runtime.RawExtension{ 37 Raw: out, 38 } 39 } 40 41 // Log implements logr.Logger for testing. Do not use if you actually want to 42 // test log messages. 43 type Log struct{} 44 45 // Init initializes the logger from runtime information. 46 func (l *Log) Init(info logr.RuntimeInfo) {} 47 48 // Error logs an error, with the given message and key/value pairs as context. 49 func (l *Log) Error(err error, msg string, keysAndValues ...interface{}) {} 50 51 // V returns a new Logger instance for a specific verbosity level, relative to this Logger. 52 func (l *Log) V(level int) logr.LogSink { return l } 53 54 // WithValues returns a new Logger instance with additional key/value pairs. 55 func (l *Log) WithValues(keysAndValues ...interface{}) logr.LogSink { return l } 56 57 // WithName returns a new Logger instance with the specified name element added to the Logger's name. 58 func (l *Log) WithName(name string) logr.LogSink { return l } 59 60 // Info logs a non-error message with the given key/value pairs as context. 61 func (l *Log) Info(level int, msg string, keysAndValues ...interface{}) {} 62 63 // Enabled tests whether this Logger is enabled. 64 func (l *Log) Enabled(level int) bool { return false }