Skip to content

Commit bc58f5e

Browse files
committed
Clean up directory before creating elements
Prevents error "Cannot link: file exists"
1 parent 0a11a51 commit bc58f5e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/test/php/com/amazon/aws/lambda/unittest/PackagingTest.class.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use io\streams\MemoryOutputStream;
55
use io\{File, Files, Folder, Path};
66
use lang\Environment;
7-
use test\{After, Assert, Before, Test};
7+
use test\{After, Assert, Before, Test, Values};
88
use util\cmd\Console;
99
use xp\lambda\{PackageLambda, Sources};
1010

@@ -31,6 +31,7 @@ private function cleanup(Folder $folder= null) {
3131

3232
/** Creates files and directory from given definitions */
3333
private function create(array $definitions): Path {
34+
$this->cleanup();
3435

3536
// Create sources from definitions
3637
foreach ($definitions as $name => $definition) {
@@ -108,16 +109,17 @@ public function file_inside_directory() {
108109
Assert::false($zip->hasNext());
109110
}
110111

111-
#[Test]
112-
public function link_inside_directory() {
112+
#[Test, Values(['../../core', '%s/core'])]
113+
public function link_inside_directory($target) {
114+
$link= sprintf($target, rtrim($this->tempDir->getURI(), DIRECTORY_SEPARATOR));
113115
$path= $this->create([
114116
'core/' => [Sources::IS_FOLDER, 0755],
115117
'core/composer.json' => [Sources::IS_FILE, '{"require":{"php":">=7.0"}}'],
116118
'project' => [Sources::IS_FOLDER, 0755],
117119
'project/src' => [Sources::IS_FOLDER, 0755],
118120
'project/src/file.txt' => [Sources::IS_FILE, 'Test'],
119121
'project/lib' => [Sources::IS_FOLDER, 0755],
120-
'project/lib/core' => [Sources::IS_LINK, '../../core'],
122+
'project/lib/core' => [Sources::IS_LINK, $link],
121123
]);
122124
$zip= $this->package(new Sources(new Path($path, 'project'), ['src', 'lib']));
123125

0 commit comments

Comments
 (0)