kubectl: move events sorting interface to the api for general use

This commit is contained in:
Michail Kargakis
2016-09-15 17:56:40 +02:00
parent 4b5c74eed8
commit b87e8c79ca
6 changed files with 32 additions and 31 deletions

View File

@@ -170,6 +170,30 @@ func TestPodDescribeResultsSorted(t *testing.T) {
VerifyDatesInOrder(out, "\n" /* rowDelimiter */, "\t" /* columnDelimiter */, t)
}
// VerifyDatesInOrder checks the start of each line for a RFC1123Z date
// and posts error if all subsequent dates are not equal or increasing
func VerifyDatesInOrder(
resultToTest, rowDelimiter, columnDelimiter string, t *testing.T) {
lines := strings.Split(resultToTest, rowDelimiter)
var previousTime time.Time
for _, str := range lines {
columns := strings.Split(str, columnDelimiter)
if len(columns) > 0 {
currentTime, err := time.Parse(time.RFC1123Z, columns[0])
if err == nil {
if previousTime.After(currentTime) {
t.Errorf(
"Output is not sorted by time. %s should be listed after %s. Complete output: %s",
previousTime.Format(time.RFC1123Z),
currentTime.Format(time.RFC1123Z),
resultToTest)
}
previousTime = currentTime
}
}
}
}
func TestDescribeContainers(t *testing.T) {
testCases := []struct {
container api.Container