mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #86832 from mattjmcnaughton/mattjmcnaughton/remove-dead-code-in-fake-docker-client
Remove dead code in fake docker client
This commit is contained in:
commit
49e24adf3e
@ -23,7 +23,6 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -270,13 +269,6 @@ func (f *FakeDockerClient) SetFakeContainers(containers []*FakeContainer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakeDockerClient) SetFakeRunningContainers(containers []*FakeContainer) {
|
|
||||||
for _, c := range containers {
|
|
||||||
c.Running = true
|
|
||||||
}
|
|
||||||
f.SetFakeContainers(containers)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeDockerClient) AssertCalls(calls []string) (err error) {
|
func (f *FakeDockerClient) AssertCalls(calls []string) (err error) {
|
||||||
f.Lock()
|
f.Lock()
|
||||||
defer f.Unlock()
|
defer f.Unlock()
|
||||||
@ -299,82 +291,6 @@ func (f *FakeDockerClient) AssertCallDetails(calls ...CalledDetail) (err error)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// idsToNames converts container ids into names. The caller must hold the lock.
|
|
||||||
func (f *FakeDockerClient) idsToNames(ids []string) ([]string, error) {
|
|
||||||
names := []string{}
|
|
||||||
for _, id := range ids {
|
|
||||||
names = append(names, strings.TrimPrefix(f.ContainerMap[id].Name, dockerNamePrefix))
|
|
||||||
}
|
|
||||||
return names, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeDockerClient) AssertCreatedByNameWithOrder(created []string) error {
|
|
||||||
f.Lock()
|
|
||||||
defer f.Unlock()
|
|
||||||
actualCreated, err := f.idsToNames(f.Created)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(created, actualCreated) {
|
|
||||||
return fmt.Errorf("expected %#v, got %#v", created, actualCreated)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeDockerClient) AssertCreatedByName(created []string) error {
|
|
||||||
f.Lock()
|
|
||||||
defer f.Unlock()
|
|
||||||
|
|
||||||
actualCreated, err := f.idsToNames(f.Created)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return sortedStringSlicesEqual(created, actualCreated)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeDockerClient) AssertStoppedByName(stopped []string) error {
|
|
||||||
f.Lock()
|
|
||||||
defer f.Unlock()
|
|
||||||
actualStopped, err := f.idsToNames(f.Stopped)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return sortedStringSlicesEqual(stopped, actualStopped)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeDockerClient) AssertStopped(stopped []string) error {
|
|
||||||
f.Lock()
|
|
||||||
defer f.Unlock()
|
|
||||||
// Copy stopped to avoid modifying it.
|
|
||||||
actualStopped := append([]string{}, f.Stopped...)
|
|
||||||
return sortedStringSlicesEqual(stopped, actualStopped)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeDockerClient) AssertImagesPulled(pulled []string) error {
|
|
||||||
f.Lock()
|
|
||||||
defer f.Unlock()
|
|
||||||
// Copy pulled to avoid modifying it.
|
|
||||||
actualPulled := append([]string{}, f.ImagesPulled...)
|
|
||||||
return sortedStringSlicesEqual(pulled, actualPulled)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeDockerClient) AssertImagesPulledMsgs(expected []string) error {
|
|
||||||
f.Lock()
|
|
||||||
defer f.Unlock()
|
|
||||||
// Copy pulled to avoid modifying it.
|
|
||||||
actual := append([]string{}, f.pulled...)
|
|
||||||
return sortedStringSlicesEqual(expected, actual)
|
|
||||||
}
|
|
||||||
|
|
||||||
func sortedStringSlicesEqual(expected, actual []string) error {
|
|
||||||
sort.StringSlice(expected).Sort()
|
|
||||||
sort.StringSlice(actual).Sort()
|
|
||||||
if !reflect.DeepEqual(expected, actual) {
|
|
||||||
return fmt.Errorf("expected %#v, got %#v", expected, actual)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeDockerClient) popError(op string) error {
|
func (f *FakeDockerClient) popError(op string) error {
|
||||||
if f.Errors == nil {
|
if f.Errors == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -398,7 +314,6 @@ func (f *FakeDockerClient) ListContainers(options dockertypes.ContainerListOptio
|
|||||||
if options.All {
|
if options.All {
|
||||||
// Although the container is not sorted, but the container with the same name should be in order,
|
// Although the container is not sorted, but the container with the same name should be in order,
|
||||||
// that is enough for us now.
|
// that is enough for us now.
|
||||||
// TODO(random-liu): Is a fully sorted array needed?
|
|
||||||
containerList = append(containerList, f.ExitedContainerList...)
|
containerList = append(containerList, f.ExitedContainerList...)
|
||||||
}
|
}
|
||||||
// Filters containers with id, only support 1 id.
|
// Filters containers with id, only support 1 id.
|
||||||
|
Loading…
Reference in New Issue
Block a user