diff --git a/yaml/model.go b/yaml/model.go index e7ce81b..0b09bd4 100644 --- a/yaml/model.go +++ b/yaml/model.go @@ -3,6 +3,7 @@ package yaml import ( "fmt" "path/filepath" + "strconv" "time" "github.com/grafana/dashboard-linter/lint" @@ -74,7 +75,8 @@ type DockerCompose struct { } type Input struct { - Path string `yaml:"path"` + Path string `yaml:"path"` + Status string `yaml:"status"` } type TestCaseDefinition struct { @@ -217,6 +219,10 @@ func validateInput(input []Input) { Expect(input).ToNot(BeEmpty(), "input is empty") for _, i := range input { Expect(i.Path).ToNot(BeEmpty(), "input path is empty") + if i.Status != "" { + _, err := strconv.ParseInt(i.Status, 10, 32) + Expect(err).To(BeNil(), "status must parse as integer or be empty") + } } } diff --git a/yaml/runner.go b/yaml/runner.go index 9ef2acc..ee4017f 100644 --- a/yaml/runner.go +++ b/yaml/runner.go @@ -3,11 +3,13 @@ package yaml import ( "context" "fmt" - "github.com/grafana/regexp" "os" "path/filepath" + "strconv" "time" + "github.com/grafana/regexp" + "github.com/grafana/oats/testhelpers/compose" "github.com/grafana/oats/testhelpers/requests" . "github.com/onsi/ginkgo/v2" @@ -112,9 +114,11 @@ func RunTestCase(c *TestCase) { func (c *TestCase) startEndpoint() *compose.ComposeEndpoint { var ctx = context.Background() + GinkgoWriter.Printf("Launching test for %s\n", c.Name) + endpoint := compose.NewEndpoint( c.CreateDockerComposeFile(), - filepath.Join(c.OutputDir, "output.log"), + filepath.Join(c.OutputDir, fmt.Sprintf("output-%s.log", c.Name)), []string{}, compose.PortsConfig{ PrometheusHTTPPort: c.PortConfig.PrometheusHTTPPort, @@ -165,7 +169,14 @@ func (r *runner) eventually(asserter func()) { for _, i := range r.testCase.Definition.Input { url := fmt.Sprintf("http://localhost:%d%s", r.testCase.PortConfig.ApplicationPort, i.Path) - err := requests.DoHTTPGet(url, 200) + status := 200 + if i.Status != "" { + parsedStatus, err := strconv.ParseInt(i.Status, 10, 64) + if err == nil { + status = int(parsedStatus) + } + } + err := requests.DoHTTPGet(url, status) g.Expect(err).ToNot(HaveOccurred(), "expected no error calling application endpoint %s", url) } diff --git a/yaml/testcase.go b/yaml/testcase.go index b2d8ac8..d8cbb4f 100644 --- a/yaml/testcase.go +++ b/yaml/testcase.go @@ -2,13 +2,14 @@ package yaml import ( "fmt" - "gopkg.in/yaml.v3" "os" "path/filepath" "regexp" "strings" "testing" "time" + + "gopkg.in/yaml.v3" ) var oatsFileRegex = regexp.MustCompile("oats.*\\.yaml") @@ -80,6 +81,7 @@ func readTestCase(testBase, filePath string, duration time.Duration) (TestCase, sep := string(filepath.Separator) name = strings.TrimPrefix(name, sep) name = strings.ReplaceAll(name, sep, "-") + name = "run" + name testCase := TestCase{ Name: name, Dir: dir,