Skip to content
This repository was archived by the owner on Aug 10, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/goss/goss.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func main() {
Usage: "Goss file to read from / write to",
EnvVar: "GOSS_FILE",
},
cli.StringSliceFlag{
Name: "additional-gossfiles, a",
Usage: "Addtional goss files to read from for validate/serve",
EnvVar: "GOSS_ADDITIONAL_FILES",
},
cli.StringFlag{
Name: "vars",
Usage: "json/yaml file containing variables for template",
Expand Down Expand Up @@ -145,6 +150,10 @@ func main() {
},
},
Action: func(c *cli.Context) error {
if len(c.GlobalStringSlice("additional-gossfiles")) > 0 {
fmt.Printf("Render does not work with additional-gossfiles\n")
os.Exit(1)
}
fmt.Print(goss.RenderJSON(c))
return nil
},
Expand Down
8 changes: 8 additions & 0 deletions docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ COMMANDS:

GLOBAL OPTIONS:
--gossfile, -g "./goss.yaml" Goss file to read from / write to [$GOSS_FILE]
--additional-gossfiles, -a Additional goss files to run
--vars value json/yaml file containing variables for template [$GOSS_VARS]
--package Package type to use [rpm, deb, apk, pacman]
--help, -h show help
Expand All @@ -74,6 +75,13 @@ Valid formats:
* **YAML** (default)
* **JSON**

### -a additional_gossfile
Additional files to read tests from. Not compatible with [render](#render).

Behaves differently to [gossfile](#gossfile). This does not attempt to merge gossfiles together, so any tests that have the same ID will all execute instead of being overwritten.

Multiple files can be specified using `-a file1.yaml -a file2.yaml`.

### --vars
The file to read variables from when rendering gossfile [templates](#templates).

Expand Down
6 changes: 3 additions & 3 deletions serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Serve(c *cli.Context) {

health := healthHandler{
c: c,
gossConfig: getGossConfig(c),
gossConfigs: getGossConfigs(c),
sys: system.New(c),
outputer: getOutputer(c),
cache: cache,
Expand All @@ -44,7 +44,7 @@ type res struct {
}
type healthHandler struct {
c *cli.Context
gossConfig GossConfig
gossConfigs []GossConfig
sys *system.System
outputer outputs.Outputer
cache *cache.Cache
Expand Down Expand Up @@ -74,7 +74,7 @@ func (h healthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.sys = system.New(h.c)
log.Printf("%v: Stale cache, running tests", r.RemoteAddr)
iStartTime := time.Now()
out := validate(h.sys, h.gossConfig, h.maxConcurrent)
out := validate(h.sys, h.gossConfigs, h.maxConcurrent)
var b bytes.Buffer
exitCode := h.outputer.Output(&b, out, iStartTime, outputConfig)
resp = res{exitCode: exitCode, b: b}
Expand Down
64 changes: 38 additions & 26 deletions validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,47 @@ import (
"github.com/urfave/cli"
)

func getGossConfig(c *cli.Context) GossConfig {
func getGossConfigs(c *cli.Context) []GossConfig {
// handle stdin
var fh *os.File
var path, source string
var gossConfig GossConfig
var gossConfigs []GossConfig
TemplateFilter = NewTemplateFilter(c.GlobalString("vars"))
specFile := c.GlobalString("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)
baseSpecFile := c.GlobalString("gossfile")
additionalSpecFiles := c.GlobalStringSlice("additional-gossfiles")
specFiles := append(additionalSpecFiles, baseSpecFile)
for _, specFile := range specFiles {
var gossConfig GossConfig
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 {
source = specFile
path = filepath.Dir(specFile)
OutStoreFormat = getStoreFormatFromFileName(specFile)
gossConfig = ReadJSON(specFile)
}
OutStoreFormat = getStoreFormatFromData(data)
gossConfig = ReadJSONData(data, true)
} else {
source = specFile
path = filepath.Dir(specFile)
OutStoreFormat = getStoreFormatFromFileName(specFile)
gossConfig = ReadJSON(specFile)
gossConfig = mergeJSONData(gossConfig, 0, path)
gossConfigs = append(gossConfigs, gossConfig)
}

gossConfig = mergeJSONData(gossConfig, 0, path)

if len(gossConfig.Resources()) == 0 {
var resourceCount int
for _, gossConfig := range gossConfigs {
resourceCount += len(gossConfig.Resources())
}
if resourceCount == 0 {
fmt.Printf("Error: found 0 tests, source: %v\n", source)
os.Exit(1)
}
return gossConfig

return gossConfigs
}

func getOutputer(c *cli.Context) outputs.Outputer {
Expand All @@ -66,7 +76,7 @@ func Validate(c *cli.Context, startTime time.Time) {
FormatOptions: c.StringSlice("format-options"),
}

gossConfig := getGossConfig(c)
gossConfigs := getGossConfigs(c)
sys := system.New(c)
outputer := getOutputer(c)

Expand All @@ -75,7 +85,7 @@ func Validate(c *cli.Context, startTime time.Time) {
i := 1
for {
iStartTime := time.Now()
out := validate(sys, gossConfig, c.Int("max-concurrent"))
out := validate(sys, gossConfigs, c.Int("max-concurrent"))
exitCode := outputer.Output(os.Stdout, out, iStartTime, outputConfig)
if retryTimeout == 0 || exitCode == 0 {
os.Exit(exitCode)
Expand All @@ -94,13 +104,15 @@ func Validate(c *cli.Context, startTime time.Time) {
}
}

func validate(sys *system.System, gossConfig GossConfig, maxConcurrent int) <-chan []resource.TestResult {
func validate(sys *system.System, gossConfigs []GossConfig, maxConcurrent int) <-chan []resource.TestResult {
out := make(chan []resource.TestResult)
in := make(chan resource.Resource)

go func() {
for _, t := range gossConfig.Resources() {
in <- t
for _, gossConfig := range gossConfigs {
for _, t := range gossConfig.Resources() {
in <- t
}
}
close(in)
}()
Expand Down