@@ -6,6 +6,7 @@ import { PullPolicy } from "../utils/pull-policy";
66import {
77 checkContainerIsHealthy ,
88 checkContainerIsHealthyUdp ,
9+ createTempSymlinkedFile ,
910 getDockerEventStream ,
1011 getRunningContainerNames ,
1112 waitForDockerEvent ,
@@ -374,6 +375,23 @@ describe("GenericContainer", { timeout: 180_000 }, () => {
374375 expect ( ( await container . exec ( [ "cat" , target ] ) ) . output ) . toEqual ( expect . stringContaining ( "hello world" ) ) ;
375376 } ) ;
376377
378+ it ( "should follow symlink when copying file to container" , async ( ) => {
379+ if ( process . platform === "win32" ) {
380+ return ;
381+ }
382+
383+ const content = `hello world ${ new RandomUuid ( ) . nextUuid ( ) } ` ;
384+ const target = "/tmp/test.txt" ;
385+ await using symlinkedFile = await createTempSymlinkedFile ( content ) ;
386+ await using container = await new GenericContainer ( "cristianrgreco/testcontainer:1.1.14" )
387+ . withCopyFilesToContainer ( [ { source : symlinkedFile . symlink , target } ] )
388+ . withExposedPorts ( 8080 )
389+ . start ( ) ;
390+
391+ expect ( ( await container . exec ( [ "cat" , target ] ) ) . output ) . toEqual ( expect . stringContaining ( content ) ) ;
392+ expect ( ( await container . exec ( [ "sh" , "-c" , `[ -L ${ target } ]` ] ) ) . exitCode ) . toBe ( 1 ) ;
393+ } ) ;
394+
377395 it ( "should copy file to container with permissions" , async ( ) => {
378396 const source = path . resolve ( fixtures , "docker" , "test.txt" ) ;
379397 const target = "/tmp/test.txt" ;
@@ -399,6 +417,24 @@ describe("GenericContainer", { timeout: 180_000 }, () => {
399417 expect ( ( await container . exec ( [ "cat" , target ] ) ) . output ) . toEqual ( expect . stringContaining ( "hello world" ) ) ;
400418 } ) ;
401419
420+ it ( "should follow symlink when copying file to started container" , async ( ) => {
421+ if ( process . platform === "win32" ) {
422+ return ;
423+ }
424+
425+ const content = `hello world ${ new RandomUuid ( ) . nextUuid ( ) } ` ;
426+ const target = "/tmp/test.txt" ;
427+ await using symlinkedFile = await createTempSymlinkedFile ( content ) ;
428+ await using container = await new GenericContainer ( "cristianrgreco/testcontainer:1.1.14" )
429+ . withExposedPorts ( 8080 )
430+ . start ( ) ;
431+
432+ await container . copyFilesToContainer ( [ { source : symlinkedFile . symlink , target } ] ) ;
433+
434+ expect ( ( await container . exec ( [ "cat" , target ] ) ) . output ) . toEqual ( expect . stringContaining ( content ) ) ;
435+ expect ( ( await container . exec ( [ "sh" , "-c" , `[ -L ${ target } ]` ] ) ) . exitCode ) . toBe ( 1 ) ;
436+ } ) ;
437+
402438 it ( "should copy directory to container" , async ( ) => {
403439 const source = path . resolve ( fixtures , "docker" ) ;
404440 const target = "/tmp" ;
0 commit comments