diff --git a/cmd/mockbackend/e2etesting.go b/cmd/mockbackend/e2etesting.go index 1cbc378b4..b6a0ebc9e 100644 --- a/cmd/mockbackend/e2etesting.go +++ b/cmd/mockbackend/e2etesting.go @@ -169,7 +169,7 @@ func isRenderEqual(m1, m2 RenderResponse) error { return nil } -func doTest(logger *zap.Logger, t *Query) []error { +func doTest(logger *zap.Logger, t *Query, verbose bool) []error { client := http.Client{} failures := make([]error, 0) d, err := time.ParseDuration(fmt.Sprintf("%v", t.Delay) + "s") @@ -270,16 +270,24 @@ func doTest(logger *zap.Logger, t *Query) []error { } if len(t.ExpectedResponse.ExpectedResults) == 0 { - if len(res) > 0 { - failures = append(failures, merry2.Errorf("unexpected amount of results, got %v, expected 0", len(res))) - } return failures } if len(res) != len(t.ExpectedResponse.ExpectedResults[0].MetricsFind) { - failures = append(failures, merry2.Errorf("unexpected amount of results, got %v, expected %v", + failures = append(failures, merry2.Errorf("unexpected amount of metrics find, got %v, expected %v", len(res), len(t.ExpectedResponse.ExpectedResults[0].MetricsFind))) + if verbose { + for i := range t.ExpectedResponse.ExpectedResults[0].MetricsFind { + if len(res) > i || !reflect.DeepEqual(res[i], t.ExpectedResponse.ExpectedResults[0].MetricsFind[i]) { + err = fmt.Errorf("metrics find[%d] are not equal, got=`%+v`, expected=`%+v`", i, res[i], t.ExpectedResponse.ExpectedResults[0].MetricsFind[i]) + failures = append(failures, err) + } else { + err = fmt.Errorf("metrics find[%d] got unexpected=`%+v`", i, t.ExpectedResponse.ExpectedResults[0].MetricsFind[i]) + } + failures = append(failures, err) + } + } return failures } @@ -300,9 +308,6 @@ func doTest(logger *zap.Logger, t *Query) []error { } if len(t.ExpectedResponse.ExpectedResults) == 0 { - if len(res) > 0 { - failures = append(failures, merry2.Errorf("unexpected amount of results, got %v, expected 0", len(res))) - } return failures } @@ -310,6 +315,17 @@ func doTest(logger *zap.Logger, t *Query) []error { failures = append(failures, merry2.Errorf("unexpected amount of results, got %v, expected %v", len(res), len(t.ExpectedResponse.ExpectedResults[0].Metrics))) + if verbose { + for i := range t.ExpectedResponse.ExpectedResults[0].Metrics { + if len(res) > i || !reflect.DeepEqual(res[i], t.ExpectedResponse.ExpectedResults[0].Metrics[i]) { + err = fmt.Errorf("metrics[%d] are not equal, got=`%+v`, expected=`%+v`", i, res[i], t.ExpectedResponse.ExpectedResults[0].Metrics[i]) + failures = append(failures, err) + } else { + err = fmt.Errorf("metrics[%d] got unexpected=`%+v`", i, t.ExpectedResponse.ExpectedResults[0].Metrics[i]) + } + failures = append(failures, err) + } + } return failures } @@ -331,7 +347,7 @@ func doTest(logger *zap.Logger, t *Query) []error { return failures } -func e2eTest(logger *zap.Logger, noapp, breakOnError bool) bool { +func e2eTest(logger *zap.Logger, noapp, breakOnError, verbose bool) bool { failed := false logger.Info("will run test", zap.Any("config", cfg.Test), @@ -355,7 +371,7 @@ func e2eTest(logger *zap.Logger, noapp, breakOnError bool) bool { } for _, t := range cfg.Test.Queries { - failures := doTest(logger, &t) + failures := doTest(logger, &t, verbose) if len(failures) != 0 { failed = true logger.Error("test failed", diff --git a/cmd/mockbackend/main.go b/cmd/mockbackend/main.go index 5424a1be6..ecfd95cbb 100644 --- a/cmd/mockbackend/main.go +++ b/cmd/mockbackend/main.go @@ -36,6 +36,7 @@ type listener struct { func main() { config := flag.String("config", "average.yaml", "yaml where it would be possible to get data") + verbose := flag.Bool("verbose", false, "verbose reporting") testonly := flag.Bool("testonly", false, "run only unit test") noapp := flag.Bool("noapp", false, "do not run application") test := flag.Bool("test", false, "run unit test if present") @@ -120,7 +121,7 @@ func main() { failed := false if cfg.Test != nil && (*test || *testonly) { - failed = e2eTest(logger, *noapp, *breakOnError) + failed = e2eTest(logger, *noapp, *breakOnError, *verbose) } if !*testonly {