diff --git a/pkg/util/fake_handler.go b/pkg/util/fake_handler.go index 3bc3b82c142..624e226b92a 100644 --- a/pkg/util/fake_handler.go +++ b/pkg/util/fake_handler.go @@ -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) diff --git a/pkg/util/set.go b/pkg/util/set.go index 7edb99d6e09..850b7f4eb20 100644 --- a/pkg/util/set.go +++ b/pkg/util/set.go @@ -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 { diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index e5d35ace438..906af1cb509 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -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" { diff --git a/pkg/util/validation.go b/pkg/util/validation.go index a78855a4ce2..ede2cd63a3f 100644 --- a/pkg/util/validation.go +++ b/pkg/util/validation.go @@ -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.