-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.go
92 lines (82 loc) · 2.16 KB
/
app.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
80
81
82
83
84
85
86
87
88
89
90
91
92
package goss
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
)
// GossRunTime represents the global runtime configs which can be set in goss
type GossRunTime struct {
//Gossfile which should holds the test config
Gossfile string
//Vars file which holds the variabesl
Vars string
//Package defines which package manager you want to use, i.e. yum, apt, ...
Package string //this does not belong here imho
//Debug on true will create a more verbose output
Debug bool
}
// Serve serves a new health endpoint
func (g *GossRunTime) Serve(endpoint string, handler *HealthHandler) {
handler.Serve(endpoint)
}
// Validate starts the validation process
func (g *GossRunTime) Validate(v *Validator) int {
return v.Validate(time.Now())
}
// Render renders a template file
func (g *GossRunTime) Render() (string, error) {
goss, err := os.Open(g.Gossfile)
if err != nil {
return "", fmt.Errorf("Could not open gossfile with error: %s", err.Error())
}
defer goss.Close()
vars, err := os.Open(g.Vars)
if err != nil {
return "", fmt.Errorf("Could not open varsfile with error: %s", err.Error())
}
defer vars.Close()
return RenderJSON(goss, vars), nil
}
// GetGossConfig returns the goss configuration
func (g *GossRunTime) GetGossConfig() GossConfig {
// handle stdin
var fh *os.File
var path, source string
var gossConfig GossConfig
TemplateFilter = NewTemplateFilter(g.Vars)
specFile := g.Gossfile
if specFile == "-" {
source = "STDIN"
fh = os.Stdin
data, err := ioutil.ReadAll(fh)
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
OutStoreFormat = getStoreFormatFromData(data)
gossConfig = ReadJSONData(data, true)
} else if specFile == "testing" {
json := []byte(`
command:
echo hello:
exit-status: 0
stdout:
- hello
timeout: 10000
`)
gossConfig = ReadJSONData(json, true)
} else {
source = specFile
path = filepath.Dir(specFile)
OutStoreFormat = getStoreFormatFromFileName(specFile)
gossConfig = ReadJSON(specFile)
}
gossConfig = mergeJSONData(gossConfig, 0, path)
if len(gossConfig.Resources()) == 0 {
fmt.Printf("Error: found 0 tests, source: %v\n", source)
os.Exit(1)
}
return gossConfig
}