@@ -687,28 +687,6 @@ func checkIrreconcilableResults(t *testing.T, key string, reconcilableError erro
687687 }
688688}
689689
690- func TestRunGetOut (t * testing.T ) {
691- o , err := runGetOut ("true" )
692- assert .Nil (t , err )
693- assert .Equal (t , len (o ), 0 )
694-
695- o , err = runGetOut ("false" )
696- assert .NotNil (t , err )
697-
698- o , err = runGetOut ("echo" , "hello" )
699- assert .Nil (t , err )
700- assert .Equal (t , string (o ), "hello\n " )
701-
702- // base64 encode "oops" so we can't match on the command arguments
703- o , err = runGetOut ("/bin/sh" , "-c" , "echo hello; echo b29wcwo= | base64 -d 1>&2; exit 1" )
704- assert .Error (t , err )
705- errtext := err .Error ()
706- assert .Contains (t , errtext , "exit status 1\n oops\n " )
707-
708- o , err = runGetOut ("/usr/bin/test-failure-to-exec-this-should-not-exist" , "arg" )
709- assert .Error (t , err )
710- }
711-
712690// TestOriginalFileBackupRestore tests backikg up and restoring original files (files that are present in the base image and
713691// get overwritten by a machine configuration)
714692func TestOriginalFileBackupRestore (t * testing.T ) {
@@ -942,3 +920,57 @@ func TestGenerateExtensionsArgs(t *testing.T) {
942920 })
943921 }
944922}
923+
924+ // MockPodmanInterface for testing podmanCopy function
925+ type MockPodmanInterface struct {
926+ createContainerFunc func (additionalArgs []string , containerName , imgURL string ) ([]byte , error )
927+ }
928+
929+ func (m * MockPodmanInterface ) GetPodmanImageInfoByReference (reference string ) (* PodmanImageInfo , error ) {
930+ return nil , fmt .Errorf ("not implemented in mock" )
931+ }
932+
933+ func (m * MockPodmanInterface ) GetPodmanInfo () (* PodmanInfo , error ) {
934+ return nil , fmt .Errorf ("not implemented in mock" )
935+ }
936+
937+ func (m * MockPodmanInterface ) CreatePodmanContainer (additionalArgs []string , containerName , imgURL string ) ([]byte , error ) {
938+ if m .createContainerFunc != nil {
939+ return m .createContainerFunc (additionalArgs , containerName , imgURL )
940+ }
941+ return []byte ("test-container-id" ), nil
942+ }
943+
944+ // Assisted by: Cursor
945+ func TestPodmanCopy_CreateContainerCall (t * testing.T ) {
946+ imgURL := "quay.io/openshift/test:latest"
947+ osImageContentDir := "/tmp/test-content"
948+
949+ // Track the call to CreatePodmanContainer
950+ var capturedArgs []string
951+ var capturedContainerName string
952+ var capturedImgURL string
953+
954+ mockPodman := & MockPodmanInterface {
955+ createContainerFunc : func (additionalArgs []string , containerName , imgURL string ) ([]byte , error ) {
956+ capturedArgs = additionalArgs
957+ capturedContainerName = containerName
958+ capturedImgURL = imgURL
959+ return []byte ("test-container-id-123" ), nil
960+ },
961+ }
962+
963+ // Note: This test will fail at podmanRemove since we're only testing the interface call
964+ // The function will return an error, but we can verify the CreatePodmanContainer was called correctly
965+ err := podmanCopy (mockPodman , imgURL , osImageContentDir )
966+
967+ // Verify the CreatePodmanContainer was called with correct parameters
968+ expectedArgs := []string {"--net=none" , "--annotation=org.openshift.machineconfigoperator.pivot=true" }
969+ assert .Equal (t , expectedArgs , capturedArgs , "CreatePodmanContainer should be called with correct additional args" )
970+ assert .Contains (t , capturedContainerName , "pivot-" , "Container name should contain pivot prefix" )
971+ assert .Equal (t , imgURL , capturedImgURL , "Image URL should match" )
972+
973+ // The function will error at podmanRemove, but that's expected in this unit test
974+ // We're only testing that the CreatePodmanContainer interface is called correctly
975+ assert .Error (t , err , "Expected error from podmanRemove since we're not mocking that part" )
976+ }
0 commit comments