func (r *FakeRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) {
	r.Lock()
	defer r.Unlock()
	r.Called = append(r.Called, "ListPodSandbox")
	if err := r.popError("ListPodSandbox"); err != nil {
		return nil, err
	}
	result := make([]*runtimeapi.PodSandbox, 0)
	for id, s := range r.Sandboxes {
		if filter != nil {
			if filter.Id != "" && filter.Id != id {
				continue
			}
			if filter.State != nil && filter.GetState().State != s.State {
				continue
			}
			if filter.LabelSelector != nil && !filterInLabels(filter.LabelSelector, s.GetLabels()) {
				continue
			}
		}
		result = append(result, &runtimeapi.PodSandbox{
			Id:             s.Id,
			Metadata:       s.Metadata,
			State:          s.State,
			CreatedAt:      s.CreatedAt,
			Labels:         s.Labels,
			Annotations:    s.Annotations,
			RuntimeHandler: s.RuntimeHandler,
		})
	}
	return result, nil
}
ListPodSandbox returns the list of pod sandboxes in the FakeRuntimeService.
package testing
import (
	"fmt"
	"reflect"
	"sync"
	"time"
	runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
)
var (
	FakeVersion = "0.1.0"
	FakeRuntimeName = "fakeRuntime"
	FakePodSandboxIPs = []string{"192.168.192.168"}
)
type FakePodSandbox struct {
	runtimeapi.PodSandboxStatus
	RuntimeHandler string
}
type FakeContainer struct {
	runtimeapi.ContainerStatus
	LinuxResources *runtimeapi.LinuxContainerResources
	SandboxID string
}
type FakeRuntimeService struct {
	sync.Mutex
	Called []string
	Errors map[string][]error
	FakeStatus          *runtimeapi.RuntimeStatus
	Containers          map[string]*FakeContainer
	Sandboxes           map[string]*FakePodSandbox
	FakeContainerStats  map[string]*runtimeapi.ContainerStats
	FakePodSandboxStats map[string]*runtimeapi.PodSandboxStats
	ErrorOnSandboxCreate bool
}
func (r *FakeRuntimeService) GetContainerID(sandboxID, name string, attempt uint32) (string, error) {
	r.Lock()
	defer r.Unlock()
	for id, c := range r.Containers {
		if c.SandboxID == sandboxID && c.Metadata.Name == name && c.Metadata.Attempt == attempt {
			return id, nil
		}
	}
	return "", fmt.Errorf("container (name, attempt, sandboxID)=(%q, %d, %q) not found", name, attempt, sandboxID)
}
func (r *FakeRuntimeService) SetFakeSandboxes(sandboxes []*FakePodSandbox) {
	r.Lock()
	defer r.Unlock()
	r.Sandboxes = make(map[string]*FakePodSandbox)
	for _, sandbox := range sandboxes {
		sandboxID := sandbox.Id
		r.Sandboxes[sandboxID] = sandbox
	}
}
func (r *FakeRuntimeService) SetFakeContainers(containers []*FakeContainer) {
	r.Lock()
	defer r.Unlock()
	r.Containers = make(map[string]*FakeContainer)
	for _, c := range containers {
		containerID := c.Id
		r.Containers[containerID] = c
	}
}
func (r *FakeRuntimeService) AssertCalls(calls []string) error {
	r.Lock()
	defer r.Unlock()
	if !reflect.DeepEqual(calls, r.Called) {
		return fmt.Errorf("expected %#v, got %#v", calls, r.Called)
	}
	return nil
}
func (r *FakeRuntimeService) GetCalls() []string {
	r.Lock()
	defer r.Unlock()
	return append([]string{}, r.Called...)
}
func (r *FakeRuntimeService) InjectError(f string, err error) {
	r.Lock()
	defer r.Unlock()
	r.Errors[f] = append(r.Errors[f], err)
}
func (r *FakeRuntimeService) popError(f string) error {
	if r.Errors == nil {
		return nil
	}
	errs := r.Errors[f]
	if len(errs) == 0 {
		return nil
	}
	err, errs := errs[0], errs[1:]
	r.Errors[f] = errs
	return err
}
func NewFakeRuntimeService() *FakeRuntimeService {
	return &FakeRuntimeService{
		Called:              make([]string, 0),
		Errors:              make(map[string][]error),
		Containers:          make(map[string]*FakeContainer),
		Sandboxes:           make(map[string]*FakePodSandbox),
		FakeContainerStats:  make(map[string]*runtimeapi.ContainerStats),
		FakePodSandboxStats: make(map[string]*runtimeapi.PodSandboxStats),
	}
}
func (r *FakeRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResponse, error) {
	r.Lock()
	defer r.Unlock()
	r.Called = append(r.Called, "Version")
	if err := r.popError("Version"); err != nil {
		return nil, err
	}
	return &runtimeapi.VersionResponse{
		Version:           FakeVersion,
		RuntimeName:       FakeRuntimeName,
		RuntimeVersion:    FakeVersion,
		RuntimeApiVersion: FakeVersion,
	}, nil
}
func (r *FakeRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
	r.Lock()
	defer r.Unlock()
	r.Called = append(r.Called, "Status")
	if err := r.popError("Status"); err != nil {
		return nil, err
	}
	return r.FakeStatus, nil
}
func (r *FakeRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string) (string, error) {
	r.Lock()
	defer r.Unlock()
	r.Called = append(r.Called, "RunPodSandbox")
	if err := r.popError("RunPodSandbox"); err != nil {
		return "", err
	}
	if r.ErrorOnSandboxCreate {
		return "", fmt.Errorf("error on sandbox create")
	}
	podSandboxID := BuildSandboxName(config.Metadata)
	createdAt := time.Now().UnixNano()
	r.Sandboxes[podSandboxID] = &FakePodSandbox{
		PodSandboxStatus: runtimeapi.PodSandboxStatus{
			Id:        podSandboxID,
			Metadata:  config.Metadata,
			State:     runtimeapi.PodSandboxState_SANDBOX_READY,
			CreatedAt: createdAt,
			Network: &runtimeapi.PodSandboxNetworkStatus{
				Ip: FakePodSandboxIPs[0],
			},
			Linux: &runtimeapi.LinuxPodSandboxStatus{
				Namespaces: &runtimeapi.Namespace{
					Options: config.GetLinux().GetSecurityContext().GetNamespaceOptions(),
				},
			},
			Labels:         config.Labels,
			Annotations:    config.Annotations,
			RuntimeHandler: runtimeHandler,
		},
		RuntimeHandler: runtimeHandler,
	}
	additionalIPs := FakePodSandboxIPs[1:]
	additionalPodIPs := make([]*runtimeapi.PodIP, 0, len(additionalIPs))
	for _, ip := range additionalIPs {
		additionalPodIPs = append(additionalPodIPs, &runtimeapi.PodIP{
			Ip: ip,
		})
	}
	r.Sandboxes[podSandboxID].PodSandboxStatus.Network.AdditionalIps = additionalPodIPs
	return podSandboxID, nil
}
func (r *FakeRuntimeService) StopPodSandbox(podSandboxID string) error {
	r.Lock()
	defer r.Unlock()
	r.Called = append(r.Called, "StopPodSandbox")
	if err := r.popError("StopPodSandbox"); err != nil {
		return err
	}
	if s, ok := r.Sandboxes[podSandboxID]; ok {
		s.State = runtimeapi.PodSandboxState_SANDBOX_NOTREADY
	} else {
		return fmt.Errorf("pod sandbox %s not found", podSandboxID)
	}
	return nil
}
func (r *FakeRuntimeService) RemovePodSandbox(podSandboxID string) error {
	r.Lock()
	defer r.Unlock()
	r.Called = append(r.Called, "RemovePodSandbox")
	if err := r.popError("RemovePodSandbox"); err != nil {
		return err
	}
	delete(r.Sandboxes, podSandboxID)
	return nil
}
func (r *FakeRuntimeService) PodSandboxStatus(podSandboxID string) (*runtimeapi.PodSandboxStatus, error) {
	r.Lock()
	defer r.Unlock()
	r.Called = append(r.Called, "PodSandboxStatus")
	if err := r.popError("PodSandboxStatus"); err != nil {
		return nil, err
	}
	s, ok := r.Sandboxes[podSandboxID]
	if !ok {
		return nil, fmt.Errorf("pod sandbox %q not found", podSandboxID)
	}
	status := s.PodSandboxStatus
	return &status, nil
}