forked from rhysd/actionlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_test.go
54 lines (51 loc) · 1.19 KB
/
parse_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package actionlint
import (
"fmt"
"os"
"path/filepath"
"testing"
)
func TestDetectFilesAsWorkflow(t *testing.T) {
dir := filepath.Join("testdata", "detect_format", "workflows")
if err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
b, err := os.ReadFile(path)
if err != nil {
panic(err)
}
_, _, sf, _ := ParseFile(path, b, FileAutoDetect)
if sf != FileWorkflow {
t.Errorf("file %s is not detected as workflow", path)
}
return nil
}); err != nil {
panic(fmt.Errorf("could not read files in %q: %w", dir, err))
}
}
func TestDetectFilesAsAction(t *testing.T) {
dir := filepath.Join("testdata", "detect_format", "actions")
if err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
b, err := os.ReadFile(path)
if err != nil {
panic(err)
}
_, _, sf, _ := ParseFile(path, b, FileAutoDetect)
if sf != FileAction {
t.Errorf("file %s is not detected as action", path)
}
return nil
}); err != nil {
panic(fmt.Errorf("could not read files in %q: %w", dir, err))
}
}