Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/runner/parallel/parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/flowexec/flow/internal/runner/engine/mocks"
"github.com/flowexec/flow/internal/runner/parallel"
testUtils "github.com/flowexec/flow/tests/utils"
"github.com/flowexec/flow/tools/builder"
"github.com/flowexec/flow/tests/utils/builder"
"github.com/flowexec/flow/types/executable"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/runner/serial/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/flowexec/flow/internal/runner/engine/mocks"
"github.com/flowexec/flow/internal/runner/serial"
testUtils "github.com/flowexec/flow/tests/utils"
"github.com/flowexec/flow/tools/builder"
"github.com/flowexec/flow/tests/utils/builder"
"github.com/flowexec/flow/types/executable"
)

Expand Down
File renamed without changes.
60 changes: 16 additions & 44 deletions tools/builder/exec.go → tests/utils/builder/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,11 @@ func ExecWithExit(opts ...Option) *executable.Executable {
func ExecWithTimeout(opts ...Option) *executable.Executable {
name := "with-timeout"
timeout := 3 * time.Second
docstring := "The `timeout` field can be set to limit the amount of time the executable will run.\n" +
"If the executable runs longer than the timeout, it will be killed and the execution will fail."
e := &executable.Executable{
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Description: docstring,
Timeout: &timeout,
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Timeout: &timeout,
Exec: &executable.ExecExecutableType{
Cmd: fmt.Sprintf("sleep %d", int(timeout.Seconds()+10)),
},
Expand All @@ -105,17 +102,10 @@ func ExecWithTimeout(opts ...Option) *executable.Executable {

func ExecWithTmpDir(opts ...Option) *executable.Executable {
name := "with-tmp-dir"
docstring := fmt.Sprintf(
"Executables will be run from a new temporary direction when the `dir` field is set to `%s`.\n"+
"If the executable is a parallel or serial executable, all sub-executables will run from the same temporary directory.\n"+
"Any files created during the execution will be deleted after the executable completes.",
executable.TmpDirLabel,
)
e := &executable.Executable{
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Description: docstring,
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Exec: &executable.ExecExecutableType{
Dir: executable.Directory(executable.TmpDirLabel),
Cmd: fmt.Sprintf("echo 'hello from %[1]s';mkdir %[1]s; cd %[1]s; pwd", name),
Expand All @@ -140,19 +130,10 @@ func ExecWithArgs(opts ...Option) *executable.Executable {
argCmds = append(argCmds, fmt.Sprintf("echo 'flag=%s, key=%s'", arg.Flag, arg.EnvKey))
}
}
docstring := "Command line arguments can be passed to the executable using the `args` field.\n" +
"Arguments can be positional or flags, and can have default values.\n" +
"**You must specify the `envKey` field for each argument and one of `pos` or `flag`** " +
"The value of the argument will be available in the environment variable specified by `envKey`.\n" +
"The first positional argument is at position 1 and following arguments are at increasing positions. " +
"Flags are specified with the defined flag value and is followed by `=` and it's value (no spaces).\n" +
"If a default value is provided, it will be used if the argument is not provided. The executable will " +
"fail if a required argument is not provided."
e := &executable.Executable{
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Description: docstring,
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Exec: &executable.ExecExecutableType{
Args: args,
Cmd: fmt.Sprintf("echo 'hello from %s'; %s", name, strings.Join(argCmds, "; ")),
Expand All @@ -167,11 +148,6 @@ func ExecWithArgs(opts ...Option) *executable.Executable {

func ExecWithParams(opts ...Option) *executable.Executable {
name := "with-params"
docstring := "Parameters can be passed to the executable using the `params` field.\n" +
"Parameters can be text, secrets, or prompts. Text parameters will be available in the environment variable " +
"specified by `envKey`. Secret parameters will be resolved from the secret store and will be available in the " +
"environment variable specified by `envKey`. Prompt parameters will prompt the user for a value and will be " +
"available in the environment variable specified by `envKey`."
params := executable.ParameterList{
{EnvKey: "PARAM1", Text: "value1"},
{EnvKey: "PARAM2", SecretRef: "flow-example-secret"},
Expand All @@ -195,10 +171,9 @@ func ExecWithParams(opts ...Option) *executable.Executable {
}
}
e := &executable.Executable{
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Description: docstring,
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Exec: &executable.ExecExecutableType{
Params: params,
Cmd: fmt.Sprintf("echo 'hello from %s'; %s", name, strings.Join(paramCmds, "; ")),
Expand All @@ -213,13 +188,10 @@ func ExecWithParams(opts ...Option) *executable.Executable {

func ExecWithLogMode(opts ...Option) *executable.Executable {
name := "with-plaintext"
docstring := "The `logMode` field can be set to change the formatting of the executable's output logs.\n" +
"Valid values are `logfmt`, `text`, `json`, and `hidden`. The default value is determined by the user's configuration."
e := &executable.Executable{
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Description: docstring,
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Exec: &executable.ExecExecutableType{
LogMode: tuikitIO.Text,
Cmd: fmt.Sprintf(
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 0 additions & 11 deletions tools/builder/parallel.go → tests/utils/builder/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import (
"github.com/flowexec/flow/types/executable"
)

const (
parallelBaseDesc = "Multiple executables can be run concurrently using a parallel executable."
)

func ParallelExecByRefConfig(opts ...Option) *executable.Executable {
name := "parallel-config"
e1 := SimpleExec(opts...)
Expand All @@ -16,9 +12,6 @@ func ParallelExecByRefConfig(opts ...Option) *executable.Executable {
Verb: "start",
Name: name,
Visibility: privateExecVisibility(),
Description: parallelBaseDesc +
"The `execs` field can be used to define the child executables with more options. " +
"This includes defining an executable inline, retries, arguments, and more.",
Parallel: &executable.ParallelExecutableType{
Execs: []executable.ParallelRefConfig{
{Ref: e1.Ref()},
Expand All @@ -45,8 +38,6 @@ func ParallelExecWithExit(opts ...Option) *executable.Executable {
Name: name,
Aliases: []string{"parallel-exit"},
Visibility: privateExecVisibility(),
Description: parallelBaseDesc +
"The `failFast` option can be set to `true` to stop the flow if a sub-executable fails.",
Parallel: &executable.ParallelExecutableType{
FailFast: &ff,
Execs: executable.ParallelRefConfigList{{Ref: e1.Ref()}, {Ref: e2.Ref()}, {Ref: e3.Ref()}},
Expand All @@ -61,8 +52,6 @@ func ParallelExecWithExit(opts ...Option) *executable.Executable {

func ParallelExecWithMaxThreads(opts ...Option) *executable.Executable {
e := ParallelExecByRefConfig(opts...)
e.Description = parallelBaseDesc +
"\n\nThe `maxThreads` option can be set to limit the number of concurrent executions."
e.Parallel.MaxThreads = 1
return e
}
52 changes: 15 additions & 37 deletions tools/builder/request.go → tests/utils/builder/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@ import (
"github.com/flowexec/flow/types/executable"
)

const (
requestBaseDesc = "Request executables send HTTP requests with the specified request and response settings.\n"
)

func RequestExec(opts ...Option) *executable.Executable {
name := "request"
docstring := requestBaseDesc +
"The `url` field is required and must be a valid URL. " +
"The `method` field is optional and defaults to `GET`.\n" +
"The `headers` field is optional and can be used to set request headers."
e := &executable.Executable{
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Description: docstring,
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Request: &executable.RequestExecutableType{
URL: "https://httpbin.org/get",
Method: "GET",
Expand All @@ -37,13 +28,10 @@ func RequestExec(opts ...Option) *executable.Executable {

func RequestExecWithBody(opts ...Option) *executable.Executable {
name := "request-with-body"
docstring := requestBaseDesc +
"The `body` field is optional and can be used to send a request body."
e := &executable.Executable{
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Description: docstring,
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Request: &executable.RequestExecutableType{
URL: "https://httpbin.org/post",
Method: "POST",
Expand All @@ -59,13 +47,10 @@ func RequestExecWithBody(opts ...Option) *executable.Executable {

func RequestExecWithTransform(opts ...Option) *executable.Executable {
name := "request-with-transform"
docstring := requestBaseDesc +
"The `transformResponse` field is optional and can be used to transform the response using an Expr expression."
e := &executable.Executable{
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Description: docstring,
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Request: &executable.RequestExecutableType{
URL: "https://httpbin.org/get",
TransformResponse: "status",
Expand All @@ -81,13 +66,10 @@ func RequestExecWithTransform(opts ...Option) *executable.Executable {

func RequestExecWithTimeout(opts ...Option) *executable.Executable {
name := "request-with-timeout"
docstring := requestBaseDesc +
"The `timeout` field is optional and can be used to set the request timeout."
e := &executable.Executable{
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Description: docstring,
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Request: &executable.RequestExecutableType{
URL: "https://httpbin.org/delay/3",
Timeout: 1,
Expand All @@ -102,14 +84,10 @@ func RequestExecWithTimeout(opts ...Option) *executable.Executable {

func RequestExecWithValidatedStatus(opts ...Option) *executable.Executable {
name := "request-with-validated-status"
docstring := requestBaseDesc +
"The `validStatusCodes` field is optional and can be used to specify the valid status codes. " +
"If the response status code is not in the list, the executable will fail."
e := &executable.Executable{
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Description: docstring,
Verb: "run",
Name: name,
Visibility: privateExecVisibility(),
Request: &executable.RequestExecutableType{
URL: "https://httpbin.org/status/400",
ValidStatusCodes: []int{200},
Expand Down
9 changes: 0 additions & 9 deletions tools/builder/serial.go → tests/utils/builder/serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import (
"github.com/flowexec/flow/types/executable"
)

const (
serialBaseDesc = "Multiple executables can be run in sequence using a serial executable.\n"
)

func SerialExecByRefConfig(opts ...Option) *executable.Executable {
name := "serial-config"
e1 := SimpleExec(opts...)
Expand All @@ -16,9 +12,6 @@ func SerialExecByRefConfig(opts ...Option) *executable.Executable {
Verb: "start",
Name: name,
Visibility: privateExecVisibility(),
Description: serialBaseDesc +
"The `execs` field can be used to define the child executables with more options. " +
"This includes defining an executable inline, retries, arguments, and more.",
Serial: &executable.SerialExecutableType{
Execs: []executable.SerialRefConfig{
{Ref: e1.Ref()},
Expand All @@ -45,8 +38,6 @@ func SerialExecWithExit(opts ...Option) *executable.Executable {
Name: name,
Aliases: []string{"serial-exit"},
Visibility: privateExecVisibility(),
Description: serialBaseDesc +
"The `failFast` option can be set to `true` to stop the executable if a sub-executable fails.",
Serial: &executable.SerialExecutableType{
FailFast: &ff,
Execs: []executable.SerialRefConfig{{Ref: e1.Ref()}, {Ref: e2.Ref()}, {Ref: e3.Ref()}},
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/flowexec/flow/internal/logger"
"github.com/flowexec/flow/internal/runner/mocks"
"github.com/flowexec/flow/internal/services/store"
"github.com/flowexec/flow/tools/builder"
"github.com/flowexec/flow/tests/utils/builder"
"github.com/flowexec/flow/types/config"
"github.com/flowexec/flow/types/workspace"
)
Expand Down
Loading