Skip to content

Commit

Permalink
Improvements to logging (#41)
Browse files Browse the repository at this point in the history
* Add extra logging, allow for custom response codes

* Prefix test runs
  • Loading branch information
grcevski authored Jun 21, 2024
1 parent 440a9ef commit 14a51d8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
8 changes: 7 additions & 1 deletion yaml/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package yaml
import (
"fmt"
"path/filepath"
"strconv"
"time"

"github.com/grafana/dashboard-linter/lint"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
}
}

Expand Down
17 changes: 14 additions & 3 deletions yaml/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 3 additions & 1 deletion yaml/testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 14a51d8

Please sign in to comment.