sigs.k8s.io/cluster-api-provider-aws@v1.5.5/pkg/cloudtest/cloudtest.go (about)

     1  /*
     2  Copyright 2018 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 AWSClusterProviderSpec 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  func (l *Log) Init(info logr.RuntimeInfo) {
    46  }
    47  
    48  // Error implements Log errors.
    49  func (l *Log) Error(err error, msg string, keysAndValues ...interface{}) {}
    50  
    51  // V returns the Logger's log level.
    52  func (l *Log) V(level int) logr.LogSink { return l }
    53  
    54  // WithValues returns logs with specific values.
    55  func (l *Log) WithValues(keysAndValues ...interface{}) logr.LogSink { return l }
    56  
    57  // WithName returns the logger with a specific name.
    58  func (l *Log) WithName(name string) logr.LogSink { return l }
    59  
    60  // Info implements info messages for the logger.
    61  func (l *Log) Info(level int, msg string, keysAndValues ...interface{}) {}
    62  
    63  // Enabled returns the state of the logger.
    64  func (l *Log) Enabled(level int) bool { return false }