-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (63 loc) · 1.65 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
testutils "github.com/crackcomm/action-test/utils"
"github.com/crackcomm/go-actions/core"
// Sources
_ "github.com/crackcomm/go-actions/source/file"
_ "github.com/crackcomm/go-actions/source/http"
// Core functions
_ "github.com/crackcomm/go-core"
)
// l - Logger
var l = log.New(os.Stdout, "[action-test] ", 0)
// dirname - json or yaml file containing tests
var dirname = "tests.json"
// sources - actions sources
var sources string
func main() {
// Parse flags and print Usage if `-tests` flag is empty.
parseFlags()
// Load tests from file
tests, err := testutils.ReadTests(dirname)
if err != nil {
l.Fatal(err)
}
// Print error when no tests
if len(tests) == 0 {
fmt.Printf("--- FAIL no tests")
return
}
// Add actions sources
for _, source := range strings.Split(sources, ",") {
core.Source(source)
}
// Run tests
results := tests.Run()
// Print results
results.Print()
}
var actionTestDesctiption = `Application action-test runs tests from JSON or YAML files against actions from different sources.`
func parseFlags() {
// Print help if --help flag or --test empty
flag.Parse()
if dirname == "" {
flag.Usage()
os.Exit(0)
}
}
// init - Adds usage to flag.Usage :)
func init() {
flag.StringVar(&dirname, "tests", "", "files or directory containing YAML or JSON tests (can be glob pattern)")
flag.StringVar(&sources, "sources", "", "actions sources (comma separated)")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of action-test:\n %s\n", actionTestDesctiption)
fmt.Fprint(os.Stderr, "\n")
fmt.Fprint(os.Stderr, "Flags:\n")
flag.PrintDefaults()
}
}