-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-libtest.go
56 lines (47 loc) · 1.22 KB
/
go-libtest.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
package main
import (
"encoding/json"
"fmt"
"github.com/SSSaaS/go-libtest/settings"
"github.com/SSSaaS/go-libtest/tests"
"io/ioutil"
"os"
"time"
)
func main() {
if len(os.Args) == 1 {
fmt.Println("Error! Must specify at least one spec file:")
fmt.Println("")
fmt.Println("Usage: go-libtest spec1.json [spec2.json ... specn.json]")
}
for i := range os.Args[1:] {
if _, err := os.Stat(os.Args[i+1]); os.IsNotExist(err) {
fmt.Printf("no such file or directory: %s", os.Args[i+1])
return
}
fmt.Println("loading specs: " + os.Args[i+1])
settings_file, err := ioutil.ReadFile(os.Args[i+1])
if err != nil {
panic(err)
}
os.RemoveAll("./tmp")
os.Mkdir("./tmp", 0777)
var settings_struct settings.Settings
err = json.Unmarshal(settings_file, &settings_struct)
if err != nil {
panic(err)
}
t1 := time.Now()
for t := range settings_struct.Tests {
test := settings_struct.Tests[t]
tester := tests.Tests{test.Method, settings_struct}
if test.Type == "XChain" {
tester.XChain(test.Data, test.Input, test.Output, test.Result)
}
}
duration := time.Since(t1)
fmt.Println("------")
fmt.Println("total:", fmt.Sprintf("%.3f", duration.Seconds()), "s\n")
os.RemoveAll("./tmp")
}
}