Update vendor files to point to kubernetes-1.12.0-beta.1

This commit is contained in:
Xing Yang
2018-09-17 18:36:04 -07:00
parent 0021c22eec
commit dc2a6df45a
764 changed files with 73120 additions and 13753 deletions

View File

@@ -166,7 +166,6 @@ func NewRequirement(key string, op selection.Operator, vals []string) (*Requirem
return nil, err
}
}
sort.Strings(vals)
return &Requirement{key: key, operator: op, strValues: vals}, nil
}
@@ -299,7 +298,9 @@ func (r *Requirement) String() string {
if len(r.strValues) == 1 {
buffer.WriteString(r.strValues[0])
} else { // only > 1 since == 0 prohibited by NewRequirement
buffer.WriteString(strings.Join(r.strValues, ","))
// normalizes value order on output, without mutating the in-memory selector representation
// also avoids normalization when it is not required, and ensures we do not mutate shared data
buffer.WriteString(strings.Join(safeSort(r.strValues), ","))
}
switch r.operator {
@@ -309,6 +310,17 @@ func (r *Requirement) String() string {
return buffer.String()
}
// safeSort sort input strings without modification
func safeSort(in []string) []string {
if sort.StringsAreSorted(in) {
return in
}
out := make([]string, len(in))
copy(out, in)
sort.Strings(out)
return out
}
// Add adds requirements to the selector. It copies the current selector returning a new one
func (lsel internalSelector) Add(reqs ...Requirement) Selector {
var sel internalSelector

View File

@@ -573,3 +573,47 @@ func TestAdd(t *testing.T) {
}
}
}
func TestSafeSort(t *testing.T) {
tests := []struct {
name string
in []string
inCopy []string
want []string
}{
{
name: "nil strings",
in: nil,
inCopy: nil,
want: nil,
},
{
name: "ordered strings",
in: []string{"bar", "foo"},
inCopy: []string{"bar", "foo"},
want: []string{"bar", "foo"},
},
{
name: "unordered strings",
in: []string{"foo", "bar"},
inCopy: []string{"foo", "bar"},
want: []string{"bar", "foo"},
},
{
name: "duplicated strings",
in: []string{"foo", "bar", "foo", "bar"},
inCopy: []string{"foo", "bar", "foo", "bar"},
want: []string{"bar", "bar", "foo", "foo"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := safeSort(tt.in); !reflect.DeepEqual(got, tt.want) {
t.Errorf("safeSort() = %v, want %v", got, tt.want)
}
if !reflect.DeepEqual(tt.in, tt.inCopy) {
t.Errorf("after safeSort(), input = %v, want %v", tt.in, tt.inCopy)
}
})
}
}