vendor: remove dep and use vndr

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-06-06 09:19:04 +02:00
parent 16f44674a4
commit 148e72d81e
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
16131 changed files with 73815 additions and 4235138 deletions

View file

@ -17,8 +17,8 @@ limitations under the License.
package field
import (
"encoding/json"
"fmt"
"reflect"
"strings"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
@ -49,14 +49,33 @@ func (v *Error) ErrorBody() string {
case ErrorTypeRequired, ErrorTypeForbidden, ErrorTypeTooLong, ErrorTypeInternal:
s = fmt.Sprintf("%s", v.Type)
default:
var bad string
badBytes, err := json.Marshal(v.BadValue)
if err != nil {
bad = err.Error()
} else {
bad = string(badBytes)
value := v.BadValue
valueType := reflect.TypeOf(value)
if value == nil || valueType == nil {
value = "null"
} else if valueType.Kind() == reflect.Ptr {
if reflectValue := reflect.ValueOf(value); reflectValue.IsNil() {
value = "null"
} else {
value = reflectValue.Elem().Interface()
}
}
switch t := value.(type) {
case int64, int32, float64, float32, bool:
// use simple printer for simple types
s = fmt.Sprintf("%s: %v", v.Type, value)
case string:
s = fmt.Sprintf("%s: %q", v.Type, t)
case fmt.Stringer:
// anything that defines String() is better than raw struct
s = fmt.Sprintf("%s: %s", v.Type, t.String())
default:
// fallback to raw struct
// TODO: internal types have panic guards against json.Marshalling to prevent
// accidental use of internal types in external serialized form. For now, use
// %#v, although it would be better to show a more expressive output in the future
s = fmt.Sprintf("%s: %#v", v.Type, value)
}
s = fmt.Sprintf("%s: %s", v.Type, bad)
}
if len(v.Detail) != 0 {
s += fmt.Sprintf(": %s", v.Detail)

View file

@ -1,158 +0,0 @@
/*
Copyright 2014 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package field
import (
"fmt"
"strings"
"testing"
)
func TestMakeFuncs(t *testing.T) {
testCases := []struct {
fn func() *Error
expected ErrorType
}{
{
func() *Error { return Invalid(NewPath("f"), "v", "d") },
ErrorTypeInvalid,
},
{
func() *Error { return NotSupported(NewPath("f"), "v", nil) },
ErrorTypeNotSupported,
},
{
func() *Error { return Duplicate(NewPath("f"), "v") },
ErrorTypeDuplicate,
},
{
func() *Error { return NotFound(NewPath("f"), "v") },
ErrorTypeNotFound,
},
{
func() *Error { return Required(NewPath("f"), "d") },
ErrorTypeRequired,
},
{
func() *Error { return InternalError(NewPath("f"), fmt.Errorf("e")) },
ErrorTypeInternal,
},
}
for _, testCase := range testCases {
err := testCase.fn()
if err.Type != testCase.expected {
t.Errorf("expected Type %q, got %q", testCase.expected, err.Type)
}
}
}
func TestErrorUsefulMessage(t *testing.T) {
s := Invalid(NewPath("foo"), "bar", "deet").Error()
t.Logf("message: %v", s)
for _, part := range []string{"foo", "bar", "deet", ErrorTypeInvalid.String()} {
if !strings.Contains(s, part) {
t.Errorf("error message did not contain expected part '%v'", part)
}
}
type complicated struct {
Baz int
Qux string
Inner interface{}
KV map[string]int
}
s = Invalid(
NewPath("foo"),
&complicated{
Baz: 1,
Qux: "aoeu",
Inner: &complicated{Qux: "asdf"},
KV: map[string]int{"Billy": 2},
},
"detail",
).Error()
t.Logf("message: %v", s)
for _, part := range []string{
"foo", ErrorTypeInvalid.String(),
"Baz", "Qux", "Inner", "KV", "detail",
"1", "aoeu", "asdf", "Billy", "2",
} {
if !strings.Contains(s, part) {
t.Errorf("error message did not contain expected part '%v'", part)
}
}
}
func TestToAggregate(t *testing.T) {
testCases := struct {
ErrList []ErrorList
NumExpectedErrs []int
}{
[]ErrorList{
nil,
{},
{Invalid(NewPath("f"), "v", "d")},
{Invalid(NewPath("f"), "v", "d"), Invalid(NewPath("f"), "v", "d")},
{Invalid(NewPath("f"), "v", "d"), InternalError(NewPath(""), fmt.Errorf("e"))},
},
[]int{
0,
0,
1,
1,
2,
},
}
if len(testCases.ErrList) != len(testCases.NumExpectedErrs) {
t.Errorf("Mismatch: length of NumExpectedErrs does not match length of ErrList")
}
for i, tc := range testCases.ErrList {
agg := tc.ToAggregate()
numErrs := 0
if agg != nil {
numErrs = len(agg.Errors())
}
if numErrs != testCases.NumExpectedErrs[i] {
t.Errorf("[%d] Expected %d, got %d", i, testCases.NumExpectedErrs[i], numErrs)
}
if len(tc) == 0 {
if agg != nil {
t.Errorf("[%d] Expected nil, got %#v", i, agg)
}
} else if agg == nil {
t.Errorf("[%d] Expected non-nil", i)
}
}
}
func TestErrListFilter(t *testing.T) {
list := ErrorList{
Invalid(NewPath("test.field"), "", ""),
Invalid(NewPath("field.test"), "", ""),
Duplicate(NewPath("test"), "value"),
}
if len(list.Filter(NewErrorTypeMatcher(ErrorTypeDuplicate))) != 2 {
t.Errorf("should not filter")
}
if len(list.Filter(NewErrorTypeMatcher(ErrorTypeInvalid))) != 1 {
t.Errorf("should filter")
}
}

View file

@ -1,123 +0,0 @@
/*
Copyright 2015 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package field
import "testing"
func TestPath(t *testing.T) {
testCases := []struct {
op func(*Path) *Path
expected string
}{
{
func(p *Path) *Path { return p },
"root",
},
{
func(p *Path) *Path { return p.Child("first") },
"root.first",
},
{
func(p *Path) *Path { return p.Child("second") },
"root.first.second",
},
{
func(p *Path) *Path { return p.Index(0) },
"root.first.second[0]",
},
{
func(p *Path) *Path { return p.Child("third") },
"root.first.second[0].third",
},
{
func(p *Path) *Path { return p.Index(93) },
"root.first.second[0].third[93]",
},
{
func(p *Path) *Path { return p.parent },
"root.first.second[0].third",
},
{
func(p *Path) *Path { return p.parent },
"root.first.second[0]",
},
{
func(p *Path) *Path { return p.Key("key") },
"root.first.second[0][key]",
},
}
root := NewPath("root")
p := root
for i, tc := range testCases {
p = tc.op(p)
if p.String() != tc.expected {
t.Errorf("[%d] Expected %q, got %q", i, tc.expected, p.String())
}
if p.Root() != root {
t.Errorf("[%d] Wrong root: %#v", i, p.Root())
}
}
}
func TestPathMultiArg(t *testing.T) {
testCases := []struct {
op func(*Path) *Path
expected string
}{
{
func(p *Path) *Path { return p },
"root.first",
},
{
func(p *Path) *Path { return p.Child("second", "third") },
"root.first.second.third",
},
{
func(p *Path) *Path { return p.Index(0) },
"root.first.second.third[0]",
},
{
func(p *Path) *Path { return p.parent },
"root.first.second.third",
},
{
func(p *Path) *Path { return p.parent },
"root.first.second",
},
{
func(p *Path) *Path { return p.parent },
"root.first",
},
{
func(p *Path) *Path { return p.parent },
"root",
},
}
root := NewPath("root", "first")
p := root
for i, tc := range testCases {
p = tc.op(p)
if p.String() != tc.expected {
t.Errorf("[%d] Expected %q, got %q", i, tc.expected, p.String())
}
if p.Root() != root.Root() {
t.Errorf("[%d] Wrong root: %#v", i, p.Root())
}
}
}

View file

@ -1,436 +0,0 @@
/*
Copyright 2014 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package validation
import (
"strings"
"testing"
)
func TestIsDNS1123Label(t *testing.T) {
goodValues := []string{
"a", "ab", "abc", "a1", "a-1", "a--1--2--b",
"0", "01", "012", "1a", "1-a", "1--a--b--2",
strings.Repeat("a", 63),
}
for _, val := range goodValues {
if msgs := IsDNS1123Label(val); len(msgs) != 0 {
t.Errorf("expected true for '%s': %v", val, msgs)
}
}
badValues := []string{
"", "A", "ABC", "aBc", "A1", "A-1", "1-A",
"-", "a-", "-a", "1-", "-1",
"_", "a_", "_a", "a_b", "1_", "_1", "1_2",
".", "a.", ".a", "a.b", "1.", ".1", "1.2",
" ", "a ", " a", "a b", "1 ", " 1", "1 2",
strings.Repeat("a", 64),
}
for _, val := range badValues {
if msgs := IsDNS1123Label(val); len(msgs) == 0 {
t.Errorf("expected false for '%s'", val)
}
}
}
func TestIsDNS1123Subdomain(t *testing.T) {
goodValues := []string{
"a", "ab", "abc", "a1", "a-1", "a--1--2--b",
"0", "01", "012", "1a", "1-a", "1--a--b--2",
"a.a", "ab.a", "abc.a", "a1.a", "a-1.a", "a--1--2--b.a",
"a.1", "ab.1", "abc.1", "a1.1", "a-1.1", "a--1--2--b.1",
"0.a", "01.a", "012.a", "1a.a", "1-a.a", "1--a--b--2",
"0.1", "01.1", "012.1", "1a.1", "1-a.1", "1--a--b--2.1",
"a.b.c.d.e", "aa.bb.cc.dd.ee", "1.2.3.4.5", "11.22.33.44.55",
strings.Repeat("a", 253),
}
for _, val := range goodValues {
if msgs := IsDNS1123Subdomain(val); len(msgs) != 0 {
t.Errorf("expected true for '%s': %v", val, msgs)
}
}
badValues := []string{
"", "A", "ABC", "aBc", "A1", "A-1", "1-A",
"-", "a-", "-a", "1-", "-1",
"_", "a_", "_a", "a_b", "1_", "_1", "1_2",
".", "a.", ".a", "a..b", "1.", ".1", "1..2",
" ", "a ", " a", "a b", "1 ", " 1", "1 2",
"A.a", "aB.a", "ab.A", "A1.a", "a1.A",
"A.1", "aB.1", "A1.1", "1A.1",
"0.A", "01.A", "012.A", "1A.a", "1a.A",
"A.B.C.D.E", "AA.BB.CC.DD.EE", "a.B.c.d.e", "aa.bB.cc.dd.ee",
"a@b", "a,b", "a_b", "a;b",
"a:b", "a%b", "a?b", "a$b",
strings.Repeat("a", 254),
}
for _, val := range badValues {
if msgs := IsDNS1123Subdomain(val); len(msgs) == 0 {
t.Errorf("expected false for '%s'", val)
}
}
}
func TestIsDNS1035Label(t *testing.T) {
goodValues := []string{
"a", "ab", "abc", "a1", "a-1", "a--1--2--b",
strings.Repeat("a", 63),
}
for _, val := range goodValues {
if msgs := IsDNS1035Label(val); len(msgs) != 0 {
t.Errorf("expected true for '%s': %v", val, msgs)
}
}
badValues := []string{
"0", "01", "012", "1a", "1-a", "1--a--b--2",
"", "A", "ABC", "aBc", "A1", "A-1", "1-A",
"-", "a-", "-a", "1-", "-1",
"_", "a_", "_a", "a_b", "1_", "_1", "1_2",
".", "a.", ".a", "a.b", "1.", ".1", "1.2",
" ", "a ", " a", "a b", "1 ", " 1", "1 2",
strings.Repeat("a", 64),
}
for _, val := range badValues {
if msgs := IsDNS1035Label(val); len(msgs) == 0 {
t.Errorf("expected false for '%s'", val)
}
}
}
func TestIsCIdentifier(t *testing.T) {
goodValues := []string{
"a", "ab", "abc", "a1", "_a", "a_", "a_b", "a_1", "a__1__2__b", "__abc_123",
"A", "AB", "AbC", "A1", "_A", "A_", "A_B", "A_1", "A__1__2__B", "__123_ABC",
}
for _, val := range goodValues {
if msgs := IsCIdentifier(val); len(msgs) != 0 {
t.Errorf("expected true for '%s': %v", val, msgs)
}
}
badValues := []string{
"", "1", "123", "1a",
"-", "a-", "-a", "1-", "-1", "1_", "1_2",
".", "a.", ".a", "a.b", "1.", ".1", "1.2",
" ", "a ", " a", "a b", "1 ", " 1", "1 2",
"#a#",
}
for _, val := range badValues {
if msgs := IsCIdentifier(val); len(msgs) == 0 {
t.Errorf("expected false for '%s'", val)
}
}
}
func TestIsValidPortNum(t *testing.T) {
goodValues := []int{1, 2, 1000, 16384, 32768, 65535}
for _, val := range goodValues {
if msgs := IsValidPortNum(val); len(msgs) != 0 {
t.Errorf("expected true for %d, got %v", val, msgs)
}
}
badValues := []int{0, -1, 65536, 100000}
for _, val := range badValues {
if msgs := IsValidPortNum(val); len(msgs) == 0 {
t.Errorf("expected false for %d", val)
}
}
}
func TestIsValidGroupId(t *testing.T) {
goodValues := []int64{0, 1, 1000, 65535, 2147483647}
for _, val := range goodValues {
if msgs := IsValidGroupId(val); len(msgs) != 0 {
t.Errorf("expected true for '%d': %v", val, msgs)
}
}
badValues := []int64{-1, -1003, 2147483648, 4147483647}
for _, val := range badValues {
if msgs := IsValidGroupId(val); len(msgs) == 0 {
t.Errorf("expected false for '%d'", val)
}
}
}
func TestIsValidUserId(t *testing.T) {
goodValues := []int64{0, 1, 1000, 65535, 2147483647}
for _, val := range goodValues {
if msgs := IsValidUserId(val); len(msgs) != 0 {
t.Errorf("expected true for '%d': %v", val, msgs)
}
}
badValues := []int64{-1, -1003, 2147483648, 4147483647}
for _, val := range badValues {
if msgs := IsValidUserId(val); len(msgs) == 0 {
t.Errorf("expected false for '%d'", val)
}
}
}
func TestIsValidPortName(t *testing.T) {
goodValues := []string{"telnet", "re-mail-ck", "pop3", "a", "a-1", "1-a", "a-1-b-2-c", "1-a-2-b-3"}
for _, val := range goodValues {
if msgs := IsValidPortName(val); len(msgs) != 0 {
t.Errorf("expected true for %q: %v", val, msgs)
}
}
badValues := []string{"longerthan15characters", "", strings.Repeat("a", 16), "12345", "1-2-3-4", "-begin", "end-", "two--hyphens", "whois++"}
for _, val := range badValues {
if msgs := IsValidPortName(val); len(msgs) == 0 {
t.Errorf("expected false for %q", val)
}
}
}
func TestIsQualifiedName(t *testing.T) {
successCases := []string{
"simple",
"now-with-dashes",
"1-starts-with-num",
"1234",
"simple/simple",
"now-with-dashes/simple",
"now-with-dashes/now-with-dashes",
"now.with.dots/simple",
"now-with.dashes-and.dots/simple",
"1-num.2-num/3-num",
"1234/5678",
"1.2.3.4/5678",
"Uppercase_Is_OK_123",
"example.com/Uppercase_Is_OK_123",
"requests.storage-foo",
strings.Repeat("a", 63),
strings.Repeat("a", 253) + "/" + strings.Repeat("b", 63),
}
for i := range successCases {
if errs := IsQualifiedName(successCases[i]); len(errs) != 0 {
t.Errorf("case[%d]: %q: expected success: %v", i, successCases[i], errs)
}
}
errorCases := []string{
"nospecialchars%^=@",
"cantendwithadash-",
"-cantstartwithadash-",
"only/one/slash",
"Example.com/abc",
"example_com/abc",
"example.com/",
"/simple",
strings.Repeat("a", 64),
strings.Repeat("a", 254) + "/abc",
}
for i := range errorCases {
if errs := IsQualifiedName(errorCases[i]); len(errs) == 0 {
t.Errorf("case[%d]: %q: expected failure", i, errorCases[i])
}
}
}
func TestIsValidLabelValue(t *testing.T) {
successCases := []string{
"simple",
"now-with-dashes",
"1-starts-with-num",
"end-with-num-1",
"1234", // only num
strings.Repeat("a", 63), // to the limit
"", // empty value
}
for i := range successCases {
if errs := IsValidLabelValue(successCases[i]); len(errs) != 0 {
t.Errorf("case %s expected success: %v", successCases[i], errs)
}
}
errorCases := []string{
"nospecialchars%^=@",
"Tama-nui-te-rā.is.Māori.sun",
"\\backslashes\\are\\bad",
"-starts-with-dash",
"ends-with-dash-",
".starts.with.dot",
"ends.with.dot.",
strings.Repeat("a", 64), // over the limit
}
for i := range errorCases {
if errs := IsValidLabelValue(errorCases[i]); len(errs) == 0 {
t.Errorf("case[%d] expected failure", i)
}
}
}
func TestIsValidIP(t *testing.T) {
goodValues := []string{
"::1",
"2a00:79e0:2:0:f1c3:e797:93c1:df80",
"::",
"2001:4860:4860::8888",
"::fff:1.1.1.1",
"1.1.1.1",
"1.1.1.01",
"255.0.0.1",
"1.0.0.0",
"0.0.0.0",
}
for _, val := range goodValues {
if msgs := IsValidIP(val); len(msgs) != 0 {
t.Errorf("expected true for %q: %v", val, msgs)
}
}
badValues := []string{
"[2001:db8:0:1]:80",
"myhost.mydomain",
"-1.0.0.0",
"[2001:db8:0:1]",
"a",
}
for _, val := range badValues {
if msgs := IsValidIP(val); len(msgs) == 0 {
t.Errorf("expected false for %q", val)
}
}
}
func TestIsHTTPHeaderName(t *testing.T) {
goodValues := []string{
// Common ones
"Accept-Encoding", "Host", "If-Modified-Since", "X-Forwarded-For",
// Weirdo, but still conforming names
"a", "ab", "abc", "a1", "-a", "a-", "a-b", "a-1", "a--1--2--b", "--abc-123",
"A", "AB", "AbC", "A1", "-A", "A-", "A-B", "A-1", "A--1--2--B", "--123-ABC",
}
for _, val := range goodValues {
if msgs := IsHTTPHeaderName(val); len(msgs) != 0 {
t.Errorf("expected true for '%s': %v", val, msgs)
}
}
badValues := []string{
"Host:", "X-Forwarded-For:", "X-@Home",
"", "_", "a_", "_a", "1_", "1_2", ".", "a.", ".a", "a.b", "1.", ".1", "1.2",
" ", "a ", " a", "a b", "1 ", " 1", "1 2", "#a#", "^", ",", ";", "=", "<",
"?", "@", "{",
}
for _, val := range badValues {
if msgs := IsHTTPHeaderName(val); len(msgs) == 0 {
t.Errorf("expected false for '%s'", val)
}
}
}
func TestIsValidPercent(t *testing.T) {
goodValues := []string{
"0%",
"00000%",
"1%",
"01%",
"99%",
"100%",
"101%",
}
for _, val := range goodValues {
if msgs := IsValidPercent(val); len(msgs) != 0 {
t.Errorf("expected true for %q: %v", val, msgs)
}
}
badValues := []string{
"",
"0",
"100",
"0.0%",
"99.9%",
"hundred",
" 1%",
"1% ",
"-0%",
"-1%",
"+1%",
}
for _, val := range badValues {
if msgs := IsValidPercent(val); len(msgs) == 0 {
t.Errorf("expected false for %q", val)
}
}
}
func TestIsConfigMapKey(t *testing.T) {
successCases := []string{
"a",
"good",
"good-good",
"still.good",
"this.is.also.good",
".so.is.this",
"THIS_IS_GOOD",
"so_is_this_17",
}
for i := range successCases {
if errs := IsConfigMapKey(successCases[i]); len(errs) != 0 {
t.Errorf("[%d] expected success: %v", i, errs)
}
}
failureCases := []string{
".",
"..",
"..bad",
"b*d",
"bad!&bad",
}
for i := range failureCases {
if errs := IsConfigMapKey(failureCases[i]); len(errs) == 0 {
t.Errorf("[%d] expected failure", i)
}
}
}
func TestIsWildcardDNS1123Subdomain(t *testing.T) {
goodValues := []string{
"*.example.com",
"*.bar.com",
"*.foo.bar.com",
}
for _, val := range goodValues {
if errs := IsWildcardDNS1123Subdomain(val); len(errs) != 0 {
t.Errorf("expected no errors for %q: %v", val, errs)
}
}
badValues := []string{
"*.*.bar.com",
"*.foo.*.com",
"*bar.com",
"f*.bar.com",
"*",
}
for _, val := range badValues {
if errs := IsWildcardDNS1123Subdomain(val); len(errs) == 0 {
t.Errorf("expected errors for %q", val)
}
}
}