mirror of https://github.com/k3s-io/k3s
fix go lint errors in util
parent
628667a2b0
commit
93def86a9e
|
@ -26,6 +26,8 @@ import (
|
|||
type TestInterface interface {
|
||||
Errorf(format string, args ...interface{})
|
||||
}
|
||||
|
||||
// LogInterface is a simple interface to allow injection of Logf to report serving errors.
|
||||
type LogInterface interface {
|
||||
Logf(format string, args ...interface{})
|
||||
}
|
||||
|
@ -53,6 +55,7 @@ func (f *FakeHandler) ServeHTTP(response http.ResponseWriter, request *http.Requ
|
|||
f.RequestBody = string(bodyReceived)
|
||||
}
|
||||
|
||||
// ValidateRequest verifies that FakeHandler received a request with expected path, method, and body.
|
||||
func (f FakeHandler) ValidateRequest(t TestInterface, expectedPath, expectedMethod string, body *string) {
|
||||
if f.RequestReceived.URL.Path != expectedPath {
|
||||
t.Errorf("Unexpected request path for request %#v, received: %q, expected: %q", f.RequestReceived, f.RequestReceived.URL.Path, expectedPath)
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
|
||||
type empty struct{}
|
||||
|
||||
// A set of strings, implemented via map[string]struct{} for minimal memory consumption.
|
||||
// StringSet is a set of strings, implemented via map[string]struct{} for minimal memory consumption.
|
||||
type StringSet map[string]empty
|
||||
|
||||
// NewStringSet creates a StringSet from a list of values.
|
||||
|
@ -50,7 +50,7 @@ func (s StringSet) Has(item string) bool {
|
|||
return contained
|
||||
}
|
||||
|
||||
// Return the contents as a sorted string slice.
|
||||
// List returns the contents as a sorted string slice.
|
||||
func (s StringSet) List() []string {
|
||||
res := make([]string, 0, len(s))
|
||||
for key := range s {
|
||||
|
|
|
@ -74,10 +74,10 @@ type IntOrStringHolder struct {
|
|||
|
||||
func TestIntOrStringUnmarshalYAML(t *testing.T) {
|
||||
{
|
||||
yaml_code_int := "val: 123\n"
|
||||
yamlCodeInt := "val: 123\n"
|
||||
|
||||
var result IntOrStringHolder
|
||||
if err := yaml.Unmarshal([]byte(yaml_code_int), &result); err != nil {
|
||||
if err := yaml.Unmarshal([]byte(yamlCodeInt), &result); err != nil {
|
||||
t.Errorf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
if result.IOrS.Kind != IntstrInt || result.IOrS.IntVal != 123 {
|
||||
|
@ -86,10 +86,10 @@ func TestIntOrStringUnmarshalYAML(t *testing.T) {
|
|||
}
|
||||
|
||||
{
|
||||
yaml_code_str := "val: \"123\"\n"
|
||||
yamlCodeStr := "val: \"123\"\n"
|
||||
|
||||
var result IntOrStringHolder
|
||||
if err := yaml.Unmarshal([]byte(yaml_code_str), &result); err != nil {
|
||||
if err := yaml.Unmarshal([]byte(yamlCodeStr), &result); err != nil {
|
||||
t.Errorf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
if result.IOrS.Kind != IntstrString || result.IOrS.StrVal != "123" {
|
||||
|
@ -134,10 +134,10 @@ func TestIntOrStringMarshalYAML(t *testing.T) {
|
|||
|
||||
func TestIntOrStringUnmarshalJSON(t *testing.T) {
|
||||
{
|
||||
json_code_int := "{\"val\": 123}"
|
||||
jsonCodeInt := "{\"val\": 123}"
|
||||
|
||||
var result IntOrStringHolder
|
||||
if err := json.Unmarshal([]byte(json_code_int), &result); err != nil {
|
||||
if err := json.Unmarshal([]byte(jsonCodeInt), &result); err != nil {
|
||||
t.Errorf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
if result.IOrS.Kind != IntstrInt || result.IOrS.IntVal != 123 {
|
||||
|
@ -146,10 +146,10 @@ func TestIntOrStringUnmarshalJSON(t *testing.T) {
|
|||
}
|
||||
|
||||
{
|
||||
json_code_str := "{\"val\": \"123\"}"
|
||||
jsonCodeStr := "{\"val\": \"123\"}"
|
||||
|
||||
var result IntOrStringHolder
|
||||
if err := json.Unmarshal([]byte(json_code_str), &result); err != nil {
|
||||
if err := json.Unmarshal([]byte(jsonCodeStr), &result); err != nil {
|
||||
t.Errorf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
if result.IOrS.Kind != IntstrString || result.IOrS.StrVal != "123" {
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
|
||||
const dnsLabelFmt string = "[a-z0-9]([-a-z0-9]*[a-z0-9])?"
|
||||
|
||||
var dnsLabelRegexp *regexp.Regexp = regexp.MustCompile("^" + dnsLabelFmt + "$")
|
||||
var dnsLabelRegexp = regexp.MustCompile("^" + dnsLabelFmt + "$")
|
||||
|
||||
const dnsLabelMaxLength int = 63
|
||||
|
||||
|
@ -34,7 +34,7 @@ func IsDNSLabel(value string) bool {
|
|||
|
||||
const dnsSubdomainFmt string = dnsLabelFmt + "(\\." + dnsLabelFmt + ")*"
|
||||
|
||||
var dnsSubdomainRegexp *regexp.Regexp = regexp.MustCompile("^" + dnsSubdomainFmt + "$")
|
||||
var dnsSubdomainRegexp = regexp.MustCompile("^" + dnsSubdomainFmt + "$")
|
||||
|
||||
const dnsSubdomainMaxLength int = 253
|
||||
|
||||
|
@ -46,7 +46,7 @@ func IsDNSSubdomain(value string) bool {
|
|||
|
||||
const cIdentifierFmt string = "[A-Za-z_][A-Za-z0-9_]*"
|
||||
|
||||
var cIdentifierRegexp *regexp.Regexp = regexp.MustCompile("^" + cIdentifierFmt + "$")
|
||||
var cIdentifierRegexp = regexp.MustCompile("^" + cIdentifierFmt + "$")
|
||||
|
||||
// IsCIdentifier tests for a string that conforms the definition of an identifier
|
||||
// in C. This checks the format, but not the length.
|
||||
|
|
Loading…
Reference in New Issue