From 83134c2a72201b3ae854e64d3565339f6e066c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Wed, 24 Jun 2020 10:05:56 +0200 Subject: [PATCH 1/3] go/oasis-test-runner/cmd/common: Verbose error when scenario not found List all available scenarios if oasis-test-runner command is invoked with an unknown scenario. --- .changelog/3044.internal.md | 4 ++++ go/oasis-test-runner/cmd/common/common.go | 10 ++++++++++ go/oasis-test-runner/cmd/root.go | 12 +++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 .changelog/3044.internal.md diff --git a/.changelog/3044.internal.md b/.changelog/3044.internal.md new file mode 100644 index 00000000000..9cf31e7220b --- /dev/null +++ b/.changelog/3044.internal.md @@ -0,0 +1,4 @@ +go/oasis-test-runner/cmd/common: Give verbose error when scenario is not found + +List all available scenarios if `oasis-test-runner` command is invoked with an +unknown scenario. diff --git a/go/oasis-test-runner/cmd/common/common.go b/go/oasis-test-runner/cmd/common/common.go index 81ba890c8bc..b7acb750877 100644 --- a/go/oasis-test-runner/cmd/common/common.go +++ b/go/oasis-test-runner/cmd/common/common.go @@ -3,6 +3,7 @@ package common import ( "fmt" + "sort" "strings" "github.com/oasisprotocol/oasis-core/go/oasis-test-runner/scenario" @@ -33,6 +34,15 @@ func GetScenarios() map[string]scenario.Scenario { return scenarios } +// GetScenarioNames returns the names of all scenarios. +func GetScenarioNames() (names []string) { + for name := range scenarios { + names = append(names, name) + } + sort.Strings(names) + return +} + // GetDefaultScenarios returns all registered default scenarios. // // This function *is not* thread-safe. diff --git a/go/oasis-test-runner/cmd/root.go b/go/oasis-test-runner/cmd/root.go index 82cf83571c2..0174aa7ce8f 100644 --- a/go/oasis-test-runner/cmd/root.go +++ b/go/oasis-test-runner/cmd/root.go @@ -268,18 +268,20 @@ func runRoot(cmd *cobra.Command, args []string) error { defer rootEnv.Cleanup() logger := logging.GetLogger("test-runner") - // Enumerate requested test cases. + // Enumerate requested scenarios. toRun := common.GetDefaultScenarios() // Run all default scenarios if not set. if vec := viper.GetStringSlice(common.CfgTest); len(vec) > 0 { toRun = nil for _, v := range vec { - n := strings.ToLower(v) + name := strings.ToLower(v) scenario, ok := common.GetScenarios()[v] if !ok { - logger.Error("unknown test case", - "test", n, + logger.Error("unknown scenario", + "scenario", name, + ) + return fmt.Errorf("root: unknown scenario: %s\nAvailable scenarios:\n%s", + name, strings.Join(common.GetScenarioNames(), "\n"), ) - return fmt.Errorf("root: unknown test case: %s", n) } toRun = append(toRun, scenario) } From f5f906b3c076290d20ea6cbd298ce548c2000513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Wed, 24 Jun 2020 10:53:43 +0200 Subject: [PATCH 2/3] go/oasis-test-runner/cmd: Don't print error messages twice Previously, Execute() called nodeCommon.EarlyLogAndExit() if there was an error running rootCmd.Execute() which in turn printed the error to stderr. The error message is printed to stdout via github.com/spf13/cobra's ExecuteC() already, so this resulted in the same error message being printed twice. --- go/oasis-test-runner/cmd/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/oasis-test-runner/cmd/root.go b/go/oasis-test-runner/cmd/root.go index 0174aa7ce8f..1e4c0c6389e 100644 --- a/go/oasis-test-runner/cmd/root.go +++ b/go/oasis-test-runner/cmd/root.go @@ -75,7 +75,7 @@ func RootCmd() *cobra.Command { // Execute spawns the main entry point after handing the config file. func Execute() { if err := rootCmd.Execute(); err != nil { - nodeCommon.EarlyLogAndExit(err) + os.Exit(1) } } From 669b33504ef5ab1f956ec6511ad8fbefcd6d2ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Wed, 24 Jun 2020 14:17:19 +0200 Subject: [PATCH 3/3] go/oasis-test-runner/cmd/cmp: Remove use of EarlyLogAndExit() Instead, return an ordinary error which is then propagated and printed to logs accordingly. --- go/oasis-test-runner/cmd/cmp/cmp.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/go/oasis-test-runner/cmd/cmp/cmp.go b/go/oasis-test-runner/cmd/cmp/cmp.go index 0237aa66ea7..2f3d45b2b6d 100644 --- a/go/oasis-test-runner/cmd/cmp/cmp.go +++ b/go/oasis-test-runner/cmd/cmp/cmp.go @@ -15,7 +15,6 @@ import ( "github.com/spf13/viper" "github.com/oasisprotocol/oasis-core/go/common/logging" - nodeCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common" "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/metrics" "github.com/oasisprotocol/oasis-core/go/oasis-test-runner/cmd/common" ) @@ -120,7 +119,7 @@ func getDuration(ctx context.Context, test string, bi *model.SampleStream) (floa query := fmt.Sprintf("%s %s == 1.0", metrics.MetricUp, bi.Metric.String()) result, warnings, err := v1api.QueryRange(ctx, query, r) if err != nil { - nodeCommon.EarlyLogAndExit(fmt.Errorf("error querying Prometheus: %w", err)) + return 0, 0, fmt.Errorf("error querying Prometheus: %w", err) } if len(warnings) > 0 { cmpLogger.Warn("warnings while querying Prometheus", "warnings", warnings) @@ -206,7 +205,7 @@ func getSummableMetric(ctx context.Context, metric string, test string, bi *mode result, warnings, err := v1api.Query(ctx, query, t) if err != nil { - nodeCommon.EarlyLogAndExit(fmt.Errorf("error querying Prometheus: %w", err)) + return 0, 0, fmt.Errorf("error querying Prometheus: %w", err) } if len(warnings) > 0 { cmpLogger.Warn("warnings while querying Prometheus", "warnings", warnings) @@ -256,7 +255,7 @@ func getNetwork(ctx context.Context, test string, bi *model.SampleStream) (float query := fmt.Sprintf("(%s %s)", rxtx, labels.String()) result, warnings, err := v1api.QueryRange(ctx, query, r) if err != nil { - nodeCommon.EarlyLogAndExit(fmt.Errorf("error querying Prometheus: %w", err)) + return 0, 0, fmt.Errorf("error querying Prometheus: %w", err) } if len(warnings) > 0 { cmpLogger.Warn("warnings while querying Prometheus", "warnings", warnings)