Permalink
Browse files

unittest: move back configuration file to test configuration

Signed-off-by: Alban Dericbourg <a.dericbourg@criteo.com>
  • Loading branch information...
adericbourg committed Sep 12, 2018
1 parent 94c93f7 commit 6529ef52b0bf07728d02380093dc5d83cdb9b778
Showing with 19 additions and 8 deletions.
  1. +4 −1 README.md
  2. +15 −7 cmd/ratool/unittest.go
View
@@ -167,6 +167,7 @@ want to test.
Example:
```yaml
config_file: config.yml
tests:
- name: "Test label"
input: |
@@ -187,11 +188,13 @@ tests:
foo.bar.baz.lol 10 1528819131000
```
The path to `config_file` is relative to the test file.
To run it:
```
$ make build
$ ./ratool unittestv --config.file config_file.yml --test.file test_file.yml
$ ./ratool unittest --test.file test_file.yml
```
The tool will exit with a non-zero code if the output of the remote adapter for the given configuration and the given
View
@@ -12,6 +12,7 @@ import (
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
)
@@ -21,8 +22,7 @@ const (
)
type unittestCmd struct {
inputConfigFile string
inputTestFile string
inputTestFile string
}
func configureUnittestCmd(app *kingpin.Application) {
@@ -31,8 +31,6 @@ func configureUnittestCmd(app *kingpin.Application) {
unittestCmd = app.Command("unittest", unittestHelp)
)
unittestCmd.Flag("config.file", "Unit-tested configuration file.").
Required().ExistingFileVar(&w.inputConfigFile)
unittestCmd.Flag("test.file", "Unit-test description file.").
Required().ExistingFileVar(&w.inputTestFile)
@@ -48,13 +46,13 @@ func (w *unittestCmd) Unittest(ctx *kingpin.ParseContext) error {
return err
}
graCfg, err := config.LoadFile(logger, w.inputConfigFile)
graCfg, err := config.LoadFile(logger, testCfg.ConfigFile)
if err != nil {
level.Error(logger).Log("err", err, "msg", "error loading remote-adapter configuration file")
return err
}
fmt.Printf("# Testing %s\n", w.inputConfigFile)
fmt.Printf("# Testing %s\n", testCfg.ConfigFile)
hasDiffs := false
for _, testContext := range testCfg.Tests {
fmt.Printf("## %s\n", testContext.Name)
@@ -130,7 +128,8 @@ func makeSamples(input string) ([]*model.Sample, error) {
}
type unittestConfig struct {
Tests []*testConfig `yaml:"tests"`
ConfigFile string `yaml:"config_file"`
Tests []*testConfig `yaml:"tests"`
}
type testConfig struct {
@@ -149,6 +148,15 @@ func loadUnittestConfig(filePath string) (*unittestConfig, error) {
return nil, err
}
// Make config file path relative to test file
testFileDir := filepath.Dir(filePath)
configFilePath := filepath.Join(testFileDir, cfg.ConfigFile)
cfg.ConfigFile, err = filepath.Abs(configFilePath)
if err != nil {
return nil, err
}
// Sanitize test definition
for _, test := range cfg.Tests {
output := strings.Split(test.Output, "\n")
sort.Strings(output)

0 comments on commit 6529ef5

Please sign in to comment.