-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1791d2d
commit d87322f
Showing
41 changed files
with
1,046 additions
and
1,049 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,92 @@ | ||
package goss | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
"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 | ||
//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) | ||
handler.Serve(endpoint) | ||
} | ||
|
||
// Validate starts the validation process | ||
func (g *GossRunTime) Validate(v *Validator) int { | ||
return v.Validate(time.Now()) | ||
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() | ||
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() | ||
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 | ||
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(` | ||
// 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 = ReadJSONData(json, true) | ||
} else { | ||
source = specFile | ||
path = filepath.Dir(specFile) | ||
OutStoreFormat = getStoreFormatFromFileName(specFile) | ||
gossConfig = ReadJSON(specFile) | ||
} | ||
|
||
gossConfig = mergeJSONData(gossConfig, 0, path) | ||
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 | ||
} | ||
if len(gossConfig.Resources()) == 0 { | ||
fmt.Printf("Error: found 0 tests, source: %v\n", source) | ||
os.Exit(1) | ||
} | ||
return gossConfig | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,32 @@ | ||
package goss | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
"github.com/stretchr/testify/assert" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test_Render_WithoutGossfile(t *testing.T) { | ||
runtime := GossRunTime{} | ||
result, err := runtime.Render() | ||
runtime := GossRunTime{} | ||
result, err := runtime.Render() | ||
|
||
assert.NotNil(t, err) | ||
assert.Equal(t, "Could not open gossfile with error: open : no such file or directory", err.Error()) | ||
assert.Empty(t, result) | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "Could not open gossfile with error: open : no such file or directory", err.Error()) | ||
assert.Empty(t, result) | ||
} | ||
|
||
|
||
func Test_Render_WithoutVarsfile(t *testing.T) { | ||
file, err := ioutil.TempFile("", "tmp_gossfile_*.yaml") | ||
defer os.Remove(file.Name()) | ||
|
||
runtime := GossRunTime{ | ||
Gossfile: file.Name(), | ||
Vars: "/invalidpath", | ||
} | ||
result, err := runtime.Render() | ||
|
||
assert.NotNil(t, err) | ||
assert.Equal(t, "Could not open varsfile with error: open /invalidpath: no such file or directory", err.Error()) | ||
assert.Empty(t, result) | ||
file, err := ioutil.TempFile("", "tmp_gossfile_*.yaml") | ||
defer os.Remove(file.Name()) | ||
|
||
runtime := GossRunTime{ | ||
Gossfile: file.Name(), | ||
Vars: "/invalidpath", | ||
} | ||
result, err := runtime.Render() | ||
|
||
assert.NotNil(t, err) | ||
assert.Equal(t, "Could not open varsfile with error: open /invalidpath: no such file or directory", err.Error()) | ||
assert.Empty(t, result) | ||
} | ||
|
Oops, something went wrong.