@@ -555,5 +555,71 @@ var _ = Describe("TensorFusionPodMutator", func() {
555555 // There should be at least 2 patches (initContainers and the container env patches)
556556 Expect (len (patch )).To (BeNumerically (">=" , 2 ))
557557 })
558+
559+ It ("should transform bash/zsh -c commands correctly" , func () {
560+ // Create a pod with bash and zsh -c commands
561+ pod := & corev1.Pod {
562+ ObjectMeta : metav1.ObjectMeta {
563+ Name : "test-command-transform" ,
564+ Namespace : "default" ,
565+ },
566+ Spec : corev1.PodSpec {
567+ Containers : []corev1.Container {
568+ {
569+ Name : "bash-container" ,
570+ Image : "test-image" ,
571+ Command : []string {"bash" , "-c" , "echo 'hello world' && ls -la" },
572+ },
573+ {
574+ Name : "zsh-container" ,
575+ Image : "test-image" ,
576+ Command : []string {"zsh" , "-c" , "echo 'special chars: $HOME \" quoted\" text'" },
577+ },
578+ {
579+ Name : "other-container" ,
580+ Image : "test-image" ,
581+ Command : []string {"sh" , "-c" , "echo 'this should not change'" },
582+ },
583+ },
584+ },
585+ }
586+
587+ clientConfig := & tfv1.ClientConfig {}
588+ containerNames := []string {"bash-container" , "zsh-container" , "other-container" }
589+ nodeSelector := map [string ]string {}
590+
591+ // Call the function that includes the command transformation
592+ mutator := & TensorFusionPodMutator {}
593+ patches , err := mutator .patchTFClient (pod , clientConfig , containerNames , nodeSelector )
594+
595+ // Verify results
596+ Expect (err ).NotTo (HaveOccurred ())
597+
598+ // Check that the patches include command transformations
599+ var bashCommandPatchFound , zshCommandPatchFound , otherCommandPatchFound bool
600+
601+ for _ , patch := range patches {
602+ // Check for command transformation patches
603+ // Command patches are applied to individual elements, not the whole array
604+ if patch .Path == "/spec/containers/0/command/0" && patch .Value == "sh" {
605+ bashCommandPatchFound = true
606+ } else if patch .Path == "/spec/containers/0/command/2" {
607+ // Third element (the command string) for bash container
608+ Expect (patch .Value ).To (ContainSubstring ("bash -c" ))
609+ } else if patch .Path == "/spec/containers/1/command/0" && patch .Value == "sh" {
610+ zshCommandPatchFound = true
611+ } else if patch .Path == "/spec/containers/1/command/2" {
612+ // Third element (the command string) for zsh container
613+ Expect (patch .Value ).To (ContainSubstring ("zsh -c" ))
614+ } else if patch .Path == "/spec/containers/2/command/0" && patch .Value == "sh" {
615+ otherCommandPatchFound = true
616+ }
617+ }
618+
619+ // Verify the right patches were found
620+ Expect (bashCommandPatchFound ).To (BeTrue (), "No patch found for bash command transformation" )
621+ Expect (zshCommandPatchFound ).To (BeTrue (), "No patch found for zsh command transformation" )
622+ Expect (otherCommandPatchFound ).To (BeFalse (), "Unexpected patch found for other container command transformation" )
623+ })
558624 })
559625})
0 commit comments