@@ -6,42 +6,33 @@ import (
6
6
"bytes"
7
7
"compress/gzip"
8
8
"context"
9
- "encoding/json"
10
9
"fmt"
11
10
"io"
12
11
"io/ioutil"
13
12
"os"
14
13
"path/filepath"
15
14
"strings"
16
15
17
- "github.com/influxdata/flux"
18
16
"github.com/influxdata/flux/ast"
19
17
"github.com/influxdata/flux/ast/astutil"
20
18
"github.com/influxdata/flux/ast/testcase"
21
19
"github.com/influxdata/flux/codes"
22
20
"github.com/influxdata/flux/dependencies/filesystem"
23
- "github.com/influxdata/flux/dependencies/testing"
24
- "github.com/influxdata/flux/dependency"
25
- "github.com/influxdata/flux/execute/executetest"
26
- "github.com/influxdata/flux/execute/table"
27
21
"github.com/influxdata/flux/fluxinit"
28
22
"github.com/influxdata/flux/internal/errors"
29
- "github.com/influxdata/flux/lang"
30
- "github.com/influxdata/flux/memory"
31
23
"github.com/influxdata/flux/parser"
32
- "github.com/influxdata/flux/runtime"
33
24
"github.com/spf13/cobra"
34
25
)
35
26
36
- type testFlags struct {
27
+ type TestFlags struct {
37
28
testNames []string
38
29
paths []string
39
30
skipTestCases []string
40
31
verbosity int
41
32
}
42
33
43
34
func TestCommand (setup TestSetupFunc ) * cobra.Command {
44
- var flags testFlags
35
+ var flags TestFlags
45
36
testCommand := & cobra.Command {
46
37
Use : "test" ,
47
38
Short : "Run flux tests" ,
@@ -61,13 +52,8 @@ func TestCommand(setup TestSetupFunc) *cobra.Command {
61
52
return testCommand
62
53
}
63
54
64
- func init () {
65
- testCommand := TestCommand (NewTestExecutor )
66
- rootCmd .AddCommand (testCommand )
67
- }
68
-
69
55
// runFluxTests invokes the test runner.
70
- func runFluxTests (setup TestSetupFunc , flags testFlags ) error {
56
+ func runFluxTests (setup TestSetupFunc , flags TestFlags ) error {
71
57
if len (flags .paths ) == 0 {
72
58
flags .paths = []string {"." }
73
59
}
@@ -639,63 +625,6 @@ type TestExecutor interface {
639
625
io.Closer
640
626
}
641
627
642
- func NewTestExecutor (ctx context.Context ) (TestExecutor , error ) {
643
- return testExecutor {}, nil
644
- }
645
-
646
- type testExecutor struct {}
647
-
648
- func (testExecutor ) Run (pkg * ast.Package ) error {
649
- jsonAST , err := json .Marshal (pkg )
650
- if err != nil {
651
- return err
652
- }
653
- c := lang.ASTCompiler {AST : jsonAST }
654
-
655
- ctx , span := dependency .Inject (context .Background (),
656
- executetest .NewTestExecuteDependencies (),
657
- testing.FrameworkConfig {},
658
- )
659
- defer span .Finish ()
660
- program , err := c .Compile (ctx , runtime .Default )
661
- if err != nil {
662
- return errors .Wrap (err , codes .Invalid , "failed to compile" )
663
- }
664
-
665
- alloc := & memory.ResourceAllocator {}
666
- query , err := program .Start (ctx , alloc )
667
- if err != nil {
668
- return errors .Wrap (err , codes .Inherit , "error while executing program" )
669
- }
670
- defer query .Done ()
671
-
672
- var output strings.Builder
673
- results := flux .NewResultIteratorFromQuery (query )
674
- for results .More () {
675
- result := results .Next ()
676
- err := result .Tables ().Do (func (tbl flux.Table ) error {
677
- // The data returned here is the result of `testing.diff`, so any result means that
678
- // a comparison of two tables showed inequality. Capture that inequality as part of the error.
679
- // XXX: rockstar (08 Dec 2020) - This could use some ergonomic work, as the diff output
680
- // is not exactly "human readable."
681
- _ , _ = fmt .Fprint (& output , table .Stringify (tbl ))
682
- return nil
683
- })
684
- if err != nil {
685
- return err
686
- }
687
- }
688
- results .Release ()
689
-
690
- err = results .Err ()
691
- if err == nil && output .Len () > 0 {
692
- err = errors .New (codes .FailedPrecondition , output .String ())
693
- }
694
- return err
695
- }
696
-
697
- func (testExecutor ) Close () error { return nil }
698
-
699
628
type fs interface {
700
629
filesystem.Service
701
630
io.Closer
0 commit comments