@@ -26,6 +26,40 @@ import (
2626
2727var TestPlatforms = []fn.Platform {{OS : "linux" , Architecture : runtime .GOARCH }}
2828
29+ func copyDir (src , dst string ) error {
30+ return filepath .Walk (src , func (path string , info fs.FileInfo , err error ) error {
31+ if err != nil {
32+ return err
33+ }
34+
35+ rel , err := filepath .Rel (src , path )
36+ if err != nil {
37+ return err
38+ }
39+
40+ target := filepath .Join (dst , rel )
41+
42+ if info .Mode ()& os .ModeSymlink != 0 {
43+ linkTarget , err := os .Readlink (path )
44+ if err != nil {
45+ return err
46+ }
47+ return os .Symlink (linkTarget , target )
48+ }
49+
50+ if info .IsDir () {
51+ return os .MkdirAll (target , info .Mode ())
52+ }
53+
54+ data , err := os .ReadFile (path )
55+ if err != nil {
56+ return err
57+ }
58+
59+ return os .WriteFile (target , data , info .Mode ())
60+ })
61+ }
62+
2963// TestBuilder_BuildGo ensures that, when given a Go Function, an OCI-compliant
3064// directory structure is created on .Build in the expected path.
3165func TestBuilder_BuildGo (t * testing.T ) {
@@ -504,13 +538,18 @@ func (l *TestLanguageBuilder) Configure(job buildJob, p v1.Platform, c v1.Config
504538 return l .ConfigureFn (job , p , c )
505539}
506540
507- // Test_validatedLinkTaarget ensures that the function disallows
541+ // Test_validatedLinkTarget ensures that the function disallows
508542// links which are absolute or refer to targets outside the given root, in
509543// addition to the basic job of returning the value of reading the link.
510544func Test_validatedLinkTarget (t * testing.T ) {
511- root := filepath .Join ("testdata" , "test-links" )
545+ tmp := t .TempDir ()
546+ root := filepath .Join (tmp , "test-links" )
547+ err := copyDir ("testdata/test-links" , root )
512548
513- err := os .Symlink ("/var/example/absolute/link" , filepath .Join (root , "absoluteLink" ))
549+ if err != nil {
550+ t .Fatalf ("failed to copy test data: %v" , err )
551+ }
552+ err = os .Symlink ("/var/example/absolute/link" , filepath .Join (root , "absoluteLink" ))
514553 if err != nil && ! errors .Is (err , os .ErrExist ) {
515554 t .Fatal (err )
516555 }
0 commit comments