-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathapp_test.go
49 lines (42 loc) · 950 Bytes
/
app_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
package main
import (
"encoding/json"
"io/ioutil"
"os"
"testing"
"github.com/aquasecurity/bench-common/check"
)
func init() {
jsonFmt = true
}
// Check that JSON format output creates valid JSON
func TestOutputResults(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "test")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpfile.Name())
outputFile = tmpfile.Name()
// TODO: JSON output summary currently requires at least one test result to generate output
summary := check.Summary{Pass: 1}
controls := check.Controls{
Groups: []*check.Group{{
ID: "ID",
Checks: []*check.Check{{
ID: "CheckID",
Type: "skip",
}},
}},
}
err = outputResults(&controls, summary)
if err != nil {
t.Fatalf("outputResults failed: %v", err)
}
output, err := ioutil.ReadFile(tmpfile.Name())
if err != nil {
t.Fatalf("failed to read file: %v", err)
}
if !json.Valid(output) {
t.Fatalf("JSON output invalid")
}
}