Merge pull request #6022 from yifan-gu/fix_tests

Fix tests
This commit is contained in:
Victor Marmol 2015-03-26 15:36:27 -07:00
commit 2a5ff5d860
2 changed files with 36 additions and 18 deletions

View File

@ -19,6 +19,7 @@ package dockertools
import (
"fmt"
"reflect"
"sort"
"sync"
"time"
@ -66,6 +67,23 @@ func (f *FakeDockerClient) AssertCalls(calls []string) (err error) {
return
}
func (f *FakeDockerClient) AssertUnorderedCalls(calls []string) (err error) {
f.Lock()
defer f.Unlock()
var actual, expected []string
copy(actual, calls)
copy(expected, f.called)
sort.StringSlice(actual).Sort()
sort.StringSlice(expected).Sort()
if !reflect.DeepEqual(actual, expected) {
err = fmt.Errorf("expected(sorted) %#v, got(sorted) %#v", expected, actual)
}
return
}
// ListContainers is a test-spy implementation of DockerInterface.ListContainers.
// It adds an entry "list" to the internal method call record.
func (f *FakeDockerClient) ListContainers(options docker.ListContainersOptions) ([]docker.APIContainers, error) {

View File

@ -27,6 +27,7 @@ import (
"path"
"reflect"
"regexp"
"sort"
"strconv"
"strings"
"sync"
@ -121,6 +122,13 @@ func verifyCalls(t *testing.T, fakeDocker *dockertools.FakeDockerClient, calls [
}
}
func verifyUnorderedCalls(t *testing.T, fakeDocker *dockertools.FakeDockerClient, calls []string) {
err := fakeDocker.AssertUnorderedCalls(calls)
if err != nil {
t.Error(err)
}
}
func verifyStringArrayEquals(t *testing.T, actual, expected []string) {
invalid := len(actual) != len(expected)
if !invalid {
@ -136,23 +144,15 @@ func verifyStringArrayEquals(t *testing.T, actual, expected []string) {
}
func verifyStringArrayEqualsAnyOrder(t *testing.T, actual, expected []string) {
invalid := len(actual) != len(expected)
if !invalid {
for _, exp := range expected {
found := false
for _, act := range actual {
if exp == act {
found = true
break
}
}
if !found {
t.Errorf("Expected element %q not found in %#v", exp, actual)
}
}
}
if invalid {
t.Errorf("Expected: %#v, Actual: %#v", expected, actual)
var act, exp []string
copy(act, actual)
copy(exp, expected)
sort.StringSlice(act).Sort()
sort.StringSlice(exp).Sort()
if !reflect.DeepEqual(exp, act) {
t.Errorf("Expected(sorted): %#v, Actual(sorted): %#v", exp, act)
}
}
@ -819,7 +819,7 @@ func TestSyncPodsDeletesWithNoPodInfraContainer(t *testing.T) {
}
waitGroup.Wait()
verifyCalls(t, fakeDocker, []string{
verifyUnorderedCalls(t, fakeDocker, []string{
"list", "list", "list", "list", "inspect_container", "inspect_container", "list", "inspect_container", "inspect_container", "stop", "create", "start", "inspect_container", "create", "start", "list", "inspect_container", "inspect_container"})
// A map iteration is used to delete containers, so must not depend on