-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellcheck_test.go
More file actions
54 lines (48 loc) · 1.15 KB
/
Copy pathshellcheck_test.go
File metadata and controls
54 lines (48 loc) · 1.15 KB
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 main
import (
"strings"
"testing"
"github.com/t-ashula/dflint/rule"
)
func TestRunShellCheck(t *testing.T) {
path, err := shellCheckPath()
if err != nil || path == "" {
t.Skip("no shellcheck found")
}
res, err := runShellCheck(path, "$foo is $BAR")
if err != nil {
t.Fatalf("err:%v\n", err)
}
if res == nil {
t.Fatalf("res:%v\n", err)
}
}
func TestShellCheckRulecheck(t *testing.T) {
path, err := shellCheckPath()
if err != nil || path == "" {
t.Skip("no shellcheck found")
}
script := `RUN echo "$foo is $BAR"`
fp := strings.NewReader(script)
ast, err := buildAST(fp)
r := shellCheckRule(path)
res := r.Validate(ast)
if res == true {
report(rule.GetResults())
t.Fatalf("failed")
}
if len(rule.GetResults()) != 1 {
report(rule.GetResults())
t.Fatalf("failed, results size should be 1")
}
detail := rule.GetResults()[0]
if detail == nil {
t.Fatalf("failed, results[0] should not be nil")
}
if detail.Rule == nil {
t.Fatalf("failed, results[0] should not be nil:%v", detail)
}
if !strings.HasPrefix(detail.Rule.Name, "SC") {
t.Fatalf("failed, results[0] should not be starts with 'SC':%s", detail.Rule.Name)
}
}