test(compose): restore missing else blocks in custom volume driver preservation

This commit is contained in:
dan5py 2025-11-23 02:13:01 +01:00 committed by Daniele Luisetto
parent 947d9d0a96
commit f4fbcc66ff
2 changed files with 20 additions and 12 deletions

View file

@ -42,7 +42,7 @@ function validateDockerComposeForInjection(string $composeYaml): void
} catch (\Exception $e) {
throw new \Exception(
'Invalid Docker Compose service name: '.$e->getMessage().
' Service names must not contain shell metacharacters.',
' Service names must not contain shell metacharacters.',
0,
$e
);
@ -71,7 +71,7 @@ function validateDockerComposeForInjection(string $composeYaml): void
} catch (\Exception $e) {
throw new \Exception(
'Invalid Docker volume definition (array syntax): '.$e->getMessage().
' Please use safe path names without shell metacharacters.',
' Please use safe path names without shell metacharacters.',
0,
$e
);
@ -87,7 +87,7 @@ function validateDockerComposeForInjection(string $composeYaml): void
} catch (\Exception $e) {
throw new \Exception(
'Invalid Docker volume definition (array syntax): '.$e->getMessage().
' Please use safe path names without shell metacharacters.',
' Please use safe path names without shell metacharacters.',
0,
$e
);
@ -329,7 +329,7 @@ function parseDockerVolumeString(string $volumeString): array
// Re-throw with more context about the volume string
throw new \Exception(
'Invalid Docker volume definition: '.$e->getMessage().
' Please use safe path names without shell metacharacters.'
' Please use safe path names without shell metacharacters.'
);
}
}
@ -346,7 +346,7 @@ function parseDockerVolumeString(string $volumeString): array
} catch (\Exception $e) {
throw new \Exception(
'Invalid Docker volume definition: '.$e->getMessage().
' Please use safe path names without shell metacharacters.'
' Please use safe path names without shell metacharacters.'
);
}
}
@ -412,7 +412,7 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int
} catch (\Exception $e) {
throw new \Exception(
'Invalid Docker Compose service name: '.$e->getMessage().
' Service names must not contain shell metacharacters.'
' Service names must not contain shell metacharacters.'
);
}
@ -741,7 +741,7 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int
} catch (\Exception $e) {
throw new \Exception(
'Invalid Docker volume definition (array syntax): '.$e->getMessage().
' Please use safe path names without shell metacharacters.'
' Please use safe path names without shell metacharacters.'
);
}
}
@ -752,7 +752,7 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int
} catch (\Exception $e) {
throw new \Exception(
'Invalid Docker volume definition (array syntax): '.$e->getMessage().
' Please use safe path names without shell metacharacters.'
' Please use safe path names without shell metacharacters.'
);
}
}
@ -866,6 +866,10 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int
'resource_type' => get_class($originalResource),
]
);
} else {
// Preserve custom volume drivers as-is without renaming or creating LocalPersistentVolume
// The volume definition already exists in top-level volumes section
// The volume will be added to $volumesParsed below to preserve it in the service
}
}
dispatch(new ServerFilesFromServerJob($originalResource));
@ -1442,7 +1446,7 @@ function serviceParser(Service $resource): Collection
} catch (\Exception $e) {
throw new \Exception(
'Invalid Docker Compose service name: '.$e->getMessage().
' Service names must not contain shell metacharacters.'
' Service names must not contain shell metacharacters.'
);
}
@ -1946,7 +1950,7 @@ function serviceParser(Service $resource): Collection
} catch (\Exception $e) {
throw new \Exception(
'Invalid Docker volume definition (array syntax): '.$e->getMessage().
' Please use safe path names without shell metacharacters.'
' Please use safe path names without shell metacharacters.'
);
}
}
@ -1957,7 +1961,7 @@ function serviceParser(Service $resource): Collection
} catch (\Exception $e) {
throw new \Exception(
'Invalid Docker volume definition (array syntax): '.$e->getMessage().
' Please use safe path names without shell metacharacters.'
' Please use safe path names without shell metacharacters.'
);
}
}
@ -2065,6 +2069,10 @@ function serviceParser(Service $resource): Collection
'resource_type' => get_class($originalResource),
]
);
} else {
// Preserve custom volume drivers as-is without renaming or creating LocalPersistentVolume
// The volume definition already exists in top-level volumes section
// The volume will be added to $volumesParsed below to preserve it in the service
}
}
dispatch(new ServerFilesFromServerJob($originalResource));

View file

@ -29,7 +29,7 @@ it('ensures custom volume drivers are preserved instead of skipped', function ()
it('verifies custom volume driver preservation logic exists in both parsing locations', function () {
$parsersFile = file_get_contents(__DIR__.'/../../bootstrap/helpers/parsers.php');
// Count occurrences of the preservation logic - should appear twice (two locations)
// Count occurrences of the preservation logic
$preservationCount = substr_count($parsersFile, '// Preserve custom volume drivers as-is without renaming or creating LocalPersistentVolume');
expect($preservationCount)->toBe(2, 'Custom volume driver preservation logic should exist in both parsing locations');
});