Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0018e60

Browse files
authoredMar 29, 2022
feat(cmd): merge and replace the main flux cli with the alternate one (#4611)
This merges the fmt and test commands into the flux cli that's been getting tested in `internal/cmd` and then it promotes the one in `internal/cmd` to `cmd`. This removes the `execute` and `repl` commands and instead makes those the default. When no parameters are used, the `repl` is started. When a parameter is used, the script is executed. In addition, the script is executed in a normal context rather than hacking it through the repl. This should make the results of running a script from the CLI be more similar to if the script were run in InfluxDB.
1 parent ffb51f8 commit 0018e60

File tree

14 files changed

+165
-553
lines changed

14 files changed

+165
-553
lines changed
 

‎Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ test-release: Dockerfile_build
195195
./gotool.sh github.com/goreleaser/goreleaser release --rm-dist --snapshot"
196196

197197

198-
bin/flux: $(STDLIB_SOURCES) $$(call go_deps,./internal/cmd/flux)
199-
$(GO_BUILD) -o ./bin/flux ./internal/cmd/flux
198+
bin/flux: $(STDLIB_SOURCES) $$(call go_deps,./cmd/flux)
199+
$(GO_BUILD) -o ./bin/flux ./cmd/flux
200200

201201

202202
libflux/target/release/fluxc: libflux

‎cmd/flux/cmd/compile.go

-62
This file was deleted.

‎cmd/flux/cmd/execute.go

-49
This file was deleted.

‎cmd/flux/cmd/repl.go

-28
This file was deleted.

‎cmd/flux/cmd/root.go

-24
This file was deleted.

‎cmd/flux/cmd/test.go

+3-74
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,33 @@ import (
66
"bytes"
77
"compress/gzip"
88
"context"
9-
"encoding/json"
109
"fmt"
1110
"io"
1211
"io/ioutil"
1312
"os"
1413
"path/filepath"
1514
"strings"
1615

17-
"github.com/influxdata/flux"
1816
"github.com/influxdata/flux/ast"
1917
"github.com/influxdata/flux/ast/astutil"
2018
"github.com/influxdata/flux/ast/testcase"
2119
"github.com/influxdata/flux/codes"
2220
"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"
2721
"github.com/influxdata/flux/fluxinit"
2822
"github.com/influxdata/flux/internal/errors"
29-
"github.com/influxdata/flux/lang"
30-
"github.com/influxdata/flux/memory"
3123
"github.com/influxdata/flux/parser"
32-
"github.com/influxdata/flux/runtime"
3324
"github.com/spf13/cobra"
3425
)
3526

36-
type testFlags struct {
27+
type TestFlags struct {
3728
testNames []string
3829
paths []string
3930
skipTestCases []string
4031
verbosity int
4132
}
4233

4334
func TestCommand(setup TestSetupFunc) *cobra.Command {
44-
var flags testFlags
35+
var flags TestFlags
4536
testCommand := &cobra.Command{
4637
Use: "test",
4738
Short: "Run flux tests",
@@ -61,13 +52,8 @@ func TestCommand(setup TestSetupFunc) *cobra.Command {
6152
return testCommand
6253
}
6354

64-
func init() {
65-
testCommand := TestCommand(NewTestExecutor)
66-
rootCmd.AddCommand(testCommand)
67-
}
68-
6955
// runFluxTests invokes the test runner.
70-
func runFluxTests(setup TestSetupFunc, flags testFlags) error {
56+
func runFluxTests(setup TestSetupFunc, flags TestFlags) error {
7157
if len(flags.paths) == 0 {
7258
flags.paths = []string{"."}
7359
}
@@ -639,63 +625,6 @@ type TestExecutor interface {
639625
io.Closer
640626
}
641627

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-
699628
type fs interface {
700629
filesystem.Service
701630
io.Closer
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.