Skip to content

Commit 6a359d4

Browse files
csweichelaledbf
authored andcommitted
[testutil] Materialise fixture test files
1 parent 7a7a1ca commit 6a359d4

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

pkg/testutil/testutil.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package testutil
22

33
import (
4+
"errors"
45
"io"
56
"os"
67
"path/filepath"
@@ -79,6 +80,20 @@ func (s Setup) Materialize() (workspaceRoot string, err error) {
7980
if err != nil {
8081
return
8182
}
83+
84+
for fn, content := range comp.Files {
85+
err = os.MkdirAll(filepath.Join(workspaceRoot, comp.Location, filepath.Dir(fn)), 0755)
86+
if errors.Is(err, os.ErrExist) {
87+
err = nil
88+
}
89+
if err != nil {
90+
return
91+
}
92+
err = os.WriteFile(filepath.Join(workspaceRoot, comp.Location, fn), []byte(content), 0644)
93+
if err != nil {
94+
return
95+
}
96+
}
8297
}
8398

8499
return

pkg/testutil/testutil_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ func TestMaterialise(t *testing.T) {
9797
{
9898
Location: "comp1",
9999
Files: map[string]string{
100-
"someFile": "content",
101-
"some/other/file": "more content",
100+
"someFile": "content",
101+
"some/other/file": "more content",
102+
"some/other/another": "more content",
102103
},
103104
Comp: leeway.Component{
104105
Constants: leeway.Arguments{

0 commit comments

Comments
 (0)