diff --git a/cmd/substation/test.go b/cmd/substation/test.go index 59a9b66e..cdded117 100644 --- a/cmd/substation/test.go +++ b/cmd/substation/test.go @@ -61,104 +61,6 @@ func memConfig(m string) (customConfig, error) { return cfg, nil } -func test(ctx context.Context, file string, cfg customConfig) error { - start := time.Now() - - // These configurations are not valid. - if len(cfg.Transforms) == 0 { - return nil - } - - if len(cfg.Tests) == 0 { - fmt.Printf("?\t%s\t[no tests]\n", file) - - return nil - } - - var failedFile bool // Tracks if any test in a file failed. - for _, test := range cfg.Tests { - // cnd asserts that the test is successful. - cnd, err := condition.New(ctx, test.Condition) - if err != nil { - fmt.Printf("FAIL\t%s\t[test error]\n", file) - - //nolint:nilerr // errors should not disrupt the test. - return nil - } - - // setup creates the test messages that are tested. - setup, err := substation.New(ctx, substation.Config{ - Transforms: test.Transforms, - }) - if err != nil { - fmt.Printf("?\t%s\t[test error]\n", file) - - //nolint:nilerr // errors should not disrupt the test. - return nil - } - - // tester contains the config that will be tested. - // This has to be done for each test to ensure - // that there is no state shared between tests. - tester, err := substation.New(ctx, cfg.Config) - if err != nil { - fmt.Printf("?\t%s\t[config error]\n", file) - - //nolint:nilerr // errors should not disrupt the test. - return nil - } - - sMsgs, err := setup.Transform(ctx, message.New().AsControl()) - if err != nil { - fmt.Printf("?\t%s\t[test error]\n", file) - - //nolint:nilerr // errors should not disrupt the test. - return nil - } - - tMsgs, err := tester.Transform(ctx, sMsgs...) - if err != nil { - fmt.Printf("?\t%s\t[config error]\n", file) - - //nolint:nilerr // errors should not disrupt the test. - return nil - } - - for _, msg := range tMsgs { - // Skip control messages because they contain no data. - if msg.IsControl() { - continue - } - - ok, err := cnd.Condition(ctx, msg) - if err != nil { - fmt.Printf("?\t%s\t[test error]\n", file) - - //nolint:nilerr // errors should not disrupt the test. - return nil - } - - if !ok { - fmt.Printf("%s\n%s\n%s\n", - fmt.Sprintf("--- FAIL: %s", test.Name), - fmt.Sprintf(" message:\t%s", msg), - fmt.Sprintf(" condition:\t%s", cnd), - ) - - failedFile = true - } - } - } - - if failedFile { - fmt.Printf("FAIL\t%s\t%s\t\n", file, time.Since(start).Round(time.Microsecond)) - } else { - fmt.Printf("ok\t%s\t%s\t\n", file, time.Since(start).Round(time.Microsecond)) - } - - return nil -} - var testCmd = &cobra.Command{ Use: "test [path to configs]", Short: "test configs",