Skip to content

Commit c9c41a3

Browse files
committed
Merge remote-tracking branch 'origin/merschformann/generalize-golden-script-tests' into merschformann/generalize-golden-script-tests
2 parents 7bbea3d + 0e10fc3 commit c9c41a3

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

golden/dag.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package golden
22

33
import (
44
"fmt"
5+
"path/filepath"
56
"sync"
67
"testing"
78
)
@@ -75,12 +76,22 @@ func DagTest(t *testing.T, cases []DagTestCase) {
7576
if nextCase.Config != nil {
7677
config = *nextCase.Config
7778
}
79+
if len(config.ScriptExtensions) == 0 {
80+
// Default script extension if none is provided.
81+
config.ScriptExtensions = []ScriptExtension{{Extension: ".sh", Command: "bash"}}
82+
}
83+
84+
// Get the script extension for the test case.
85+
ext, err := dagGetScriptExtension(nextCase.Path, config)
86+
if err != nil {
87+
t.Fatal(err)
88+
}
7889

79-
nextCase := nextCase
90+
nextCase := nextCase // Capture the variable for the goroutine.
8091
go func() {
92+
defer wg.Done()
8193
// Run the test case.
82-
BashTestFile(t, nextCase.Path, config)
83-
wg.Done()
94+
ScriptTestFile(t, ext.Command, nextCase.Path, config)
8495
}()
8596
}
8697

@@ -100,6 +111,18 @@ func DagTest(t *testing.T, cases []DagTestCase) {
100111
}
101112
}
102113

114+
func dagGetScriptExtension(path string, config ScriptConfig) (ScriptExtension, error) {
115+
// Get extension from the path.
116+
ext := filepath.Ext(path)
117+
// Search for fitting script definition among config.ScriptExtensions.
118+
for _, def := range config.ScriptExtensions {
119+
if def.Extension == ext {
120+
return def, nil
121+
}
122+
}
123+
return ScriptExtension{}, fmt.Errorf("no script definition found for path %s with extension %s", path, ext)
124+
}
125+
103126
func validate(cases []DagTestCase) error {
104127
// Ensure that all cases have unique names.
105128
names := make(map[string]bool)

0 commit comments

Comments
 (0)