MCPcopy
hub / github.com/microsoft/retina / TestDownloadServiceMethods

Function TestDownloadServiceMethods

cli/cmd/capture/download_test.go:547–621  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

545}
546
547func TestDownloadServiceMethods(t *testing.T) {
548 ctx := context.Background()
549
550 // Setup test objects
551 objects := []runtime.Object{
552 NewLinuxNode("test-node"),
553 NewDownloadNamespace("test-namespace"),
554 }
555
556 kubeClient := newDownloadKubeClient(objects)
557 config := &rest.Config{}
558 service := NewDownloadService(kubeClient, config, "test-namespace")
559
560 t.Run("createDownloadPod creates pod correctly", func(t *testing.T) {
561 downloadCmd := &DownloadCmd{
562 ContainerImage: "mcr.microsoft.com/azurelinux/busybox:1.36",
563 MountPath: "/host/tmp/captures",
564 KeepAliveCommand: []string{"sh", "-c", "echo 'Download pod ready'; sleep 3600"},
565 }
566
567 pod, err := service.createDownloadPod(ctx, "test-node", "/tmp/captures", testCapture, downloadCmd)
568 if err != nil {
569 t.Fatalf("Expected no error, got: %v", err)
570 }
571
572 if pod == nil {
573 t.Fatal("Expected pod to be created, got nil")
574 }
575
576 if pod.Spec.NodeName != "test-node" {
577 t.Errorf("Expected NodeName to be 'test-node', got: %s", pod.Spec.NodeName)
578 }
579
580 if len(pod.Spec.Containers) != 1 {
581 t.Errorf("Expected 1 container, got: %d", len(pod.Spec.Containers))
582 }
583
584 container := pod.Spec.Containers[0]
585 if container.Image != downloadCmd.ContainerImage {
586 t.Errorf("Expected container image %s, got: %s", downloadCmd.ContainerImage, container.Image)
587 }
588 })
589
590 t.Run("waitForPodReady handles pod states correctly", func(t *testing.T) {
591 // This test is limited due to the fake client behavior
592 // In a real scenario, we would test timeout and different pod phases
593 podName := "test-pod-ready"
594
595 // Create a pod that should be running
596 pod := &corev1.Pod{
597 ObjectMeta: metav1.ObjectMeta{
598 Name: podName,
599 Namespace: service.namespace,
600 },
601 Status: corev1.PodStatus{
602 Phase: corev1.PodRunning,
603 },
604 }

Callers

nothing calls this directly

Calls 8

createDownloadPodMethod · 0.95
waitForPodReadyMethod · 0.95
NewLinuxNodeFunction · 0.85
NewDownloadNamespaceFunction · 0.85
newDownloadKubeClientFunction · 0.85
NewDownloadServiceFunction · 0.85
RunMethod · 0.65
CreateMethod · 0.45

Tested by

no test coverage detected