1// +build functional
2
3package cri_containerd
4
5import (
6	"context"
7	"testing"
8
9	runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
10)
11
12func runPodSandbox(t *testing.T, client runtime.RuntimeServiceClient, ctx context.Context, request *runtime.RunPodSandboxRequest) string {
13	response, err := client.RunPodSandbox(ctx, request)
14	if err != nil {
15		t.Fatalf("failed RunPodSandbox request with: %v", err)
16	}
17	return response.PodSandboxId
18}
19
20func stopPodSandbox(t *testing.T, client runtime.RuntimeServiceClient, ctx context.Context, podID string) {
21	_, err := client.StopPodSandbox(ctx, &runtime.StopPodSandboxRequest{
22		PodSandboxId: podID,
23	})
24	if err != nil {
25		t.Fatalf("failed StopPodSandbox for sandbox: %s, request with: %v", podID, err)
26	}
27}
28
29func removePodSandbox(t *testing.T, client runtime.RuntimeServiceClient, ctx context.Context, podID string) {
30	_, err := client.RemovePodSandbox(ctx, &runtime.RemovePodSandboxRequest{
31		PodSandboxId: podID,
32	})
33	if err != nil {
34		t.Fatalf("failed RemovePodSandbox for sandbox: %s, request with: %v", podID, err)
35	}
36}
37
38func getRunPodSandboxRequest(t *testing.T, runtimeHandler string) *runtime.RunPodSandboxRequest {
39	return &runtime.RunPodSandboxRequest{
40		Config: &runtime.PodSandboxConfig{
41			Metadata: &runtime.PodSandboxMetadata{
42				Name:      t.Name(),
43				Namespace: testNamespace,
44			},
45		},
46		RuntimeHandler: runtimeHandler,
47	}
48}
49