Skip to content

Commit e428e53

Browse files
authored
test: move test flowfile builder (#286)
1 parent 48fe60a commit e428e53

File tree

10 files changed

+34
-104
lines changed

10 files changed

+34
-104
lines changed

internal/runner/parallel/parallel_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/flowexec/flow/internal/runner/engine/mocks"
1616
"github.com/flowexec/flow/internal/runner/parallel"
1717
testUtils "github.com/flowexec/flow/tests/utils"
18-
"github.com/flowexec/flow/tools/builder"
18+
"github.com/flowexec/flow/tests/utils/builder"
1919
"github.com/flowexec/flow/types/executable"
2020
)
2121

internal/runner/serial/serial_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/flowexec/flow/internal/runner/engine/mocks"
1616
"github.com/flowexec/flow/internal/runner/serial"
1717
testUtils "github.com/flowexec/flow/tests/utils"
18-
"github.com/flowexec/flow/tools/builder"
18+
"github.com/flowexec/flow/tests/utils/builder"
1919
"github.com/flowexec/flow/types/executable"
2020
)
2121

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,11 @@ func ExecWithExit(opts ...Option) *executable.Executable {
8484
func ExecWithTimeout(opts ...Option) *executable.Executable {
8585
name := "with-timeout"
8686
timeout := 3 * time.Second
87-
docstring := "The `timeout` field can be set to limit the amount of time the executable will run.\n" +
88-
"If the executable runs longer than the timeout, it will be killed and the execution will fail."
8987
e := &executable.Executable{
90-
Verb: "run",
91-
Name: name,
92-
Visibility: privateExecVisibility(),
93-
Description: docstring,
94-
Timeout: &timeout,
88+
Verb: "run",
89+
Name: name,
90+
Visibility: privateExecVisibility(),
91+
Timeout: &timeout,
9592
Exec: &executable.ExecExecutableType{
9693
Cmd: fmt.Sprintf("sleep %d", int(timeout.Seconds()+10)),
9794
},
@@ -105,17 +102,10 @@ func ExecWithTimeout(opts ...Option) *executable.Executable {
105102

106103
func ExecWithTmpDir(opts ...Option) *executable.Executable {
107104
name := "with-tmp-dir"
108-
docstring := fmt.Sprintf(
109-
"Executables will be run from a new temporary direction when the `dir` field is set to `%s`.\n"+
110-
"If the executable is a parallel or serial executable, all sub-executables will run from the same temporary directory.\n"+
111-
"Any files created during the execution will be deleted after the executable completes.",
112-
executable.TmpDirLabel,
113-
)
114105
e := &executable.Executable{
115-
Verb: "run",
116-
Name: name,
117-
Visibility: privateExecVisibility(),
118-
Description: docstring,
106+
Verb: "run",
107+
Name: name,
108+
Visibility: privateExecVisibility(),
119109
Exec: &executable.ExecExecutableType{
120110
Dir: executable.Directory(executable.TmpDirLabel),
121111
Cmd: fmt.Sprintf("echo 'hello from %[1]s';mkdir %[1]s; cd %[1]s; pwd", name),
@@ -140,19 +130,10 @@ func ExecWithArgs(opts ...Option) *executable.Executable {
140130
argCmds = append(argCmds, fmt.Sprintf("echo 'flag=%s, key=%s'", arg.Flag, arg.EnvKey))
141131
}
142132
}
143-
docstring := "Command line arguments can be passed to the executable using the `args` field.\n" +
144-
"Arguments can be positional or flags, and can have default values.\n" +
145-
"**You must specify the `envKey` field for each argument and one of `pos` or `flag`** " +
146-
"The value of the argument will be available in the environment variable specified by `envKey`.\n" +
147-
"The first positional argument is at position 1 and following arguments are at increasing positions. " +
148-
"Flags are specified with the defined flag value and is followed by `=` and it's value (no spaces).\n" +
149-
"If a default value is provided, it will be used if the argument is not provided. The executable will " +
150-
"fail if a required argument is not provided."
151133
e := &executable.Executable{
152-
Verb: "run",
153-
Name: name,
154-
Visibility: privateExecVisibility(),
155-
Description: docstring,
134+
Verb: "run",
135+
Name: name,
136+
Visibility: privateExecVisibility(),
156137
Exec: &executable.ExecExecutableType{
157138
Args: args,
158139
Cmd: fmt.Sprintf("echo 'hello from %s'; %s", name, strings.Join(argCmds, "; ")),
@@ -167,11 +148,6 @@ func ExecWithArgs(opts ...Option) *executable.Executable {
167148

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

214189
func ExecWithLogMode(opts ...Option) *executable.Executable {
215190
name := "with-plaintext"
216-
docstring := "The `logMode` field can be set to change the formatting of the executable's output logs.\n" +
217-
"Valid values are `logfmt`, `text`, `json`, and `hidden`. The default value is determined by the user's configuration."
218191
e := &executable.Executable{
219-
Verb: "run",
220-
Name: name,
221-
Visibility: privateExecVisibility(),
222-
Description: docstring,
192+
Verb: "run",
193+
Name: name,
194+
Visibility: privateExecVisibility(),
223195
Exec: &executable.ExecExecutableType{
224196
LogMode: tuikitIO.Text,
225197
Cmd: fmt.Sprintf(
Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import (
44
"github.com/flowexec/flow/types/executable"
55
)
66

7-
const (
8-
parallelBaseDesc = "Multiple executables can be run concurrently using a parallel executable."
9-
)
10-
117
func ParallelExecByRefConfig(opts ...Option) *executable.Executable {
128
name := "parallel-config"
139
e1 := SimpleExec(opts...)
@@ -16,9 +12,6 @@ func ParallelExecByRefConfig(opts ...Option) *executable.Executable {
1612
Verb: "start",
1713
Name: name,
1814
Visibility: privateExecVisibility(),
19-
Description: parallelBaseDesc +
20-
"The `execs` field can be used to define the child executables with more options. " +
21-
"This includes defining an executable inline, retries, arguments, and more.",
2215
Parallel: &executable.ParallelExecutableType{
2316
Execs: []executable.ParallelRefConfig{
2417
{Ref: e1.Ref()},
@@ -45,8 +38,6 @@ func ParallelExecWithExit(opts ...Option) *executable.Executable {
4538
Name: name,
4639
Aliases: []string{"parallel-exit"},
4740
Visibility: privateExecVisibility(),
48-
Description: parallelBaseDesc +
49-
"The `failFast` option can be set to `true` to stop the flow if a sub-executable fails.",
5041
Parallel: &executable.ParallelExecutableType{
5142
FailFast: &ff,
5243
Execs: executable.ParallelRefConfigList{{Ref: e1.Ref()}, {Ref: e2.Ref()}, {Ref: e3.Ref()}},
@@ -61,8 +52,6 @@ func ParallelExecWithExit(opts ...Option) *executable.Executable {
6152

6253
func ParallelExecWithMaxThreads(opts ...Option) *executable.Executable {
6354
e := ParallelExecByRefConfig(opts...)
64-
e.Description = parallelBaseDesc +
65-
"\n\nThe `maxThreads` option can be set to limit the number of concurrent executions."
6655
e.Parallel.MaxThreads = 1
6756
return e
6857
}
Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,12 @@ import (
44
"github.com/flowexec/flow/types/executable"
55
)
66

7-
const (
8-
requestBaseDesc = "Request executables send HTTP requests with the specified request and response settings.\n"
9-
)
10-
117
func RequestExec(opts ...Option) *executable.Executable {
128
name := "request"
13-
docstring := requestBaseDesc +
14-
"The `url` field is required and must be a valid URL. " +
15-
"The `method` field is optional and defaults to `GET`.\n" +
16-
"The `headers` field is optional and can be used to set request headers."
179
e := &executable.Executable{
18-
Verb: "run",
19-
Name: name,
20-
Visibility: privateExecVisibility(),
21-
Description: docstring,
10+
Verb: "run",
11+
Name: name,
12+
Visibility: privateExecVisibility(),
2213
Request: &executable.RequestExecutableType{
2314
URL: "https://httpbin.org/get",
2415
Method: "GET",
@@ -37,13 +28,10 @@ func RequestExec(opts ...Option) *executable.Executable {
3728

3829
func RequestExecWithBody(opts ...Option) *executable.Executable {
3930
name := "request-with-body"
40-
docstring := requestBaseDesc +
41-
"The `body` field is optional and can be used to send a request body."
4231
e := &executable.Executable{
43-
Verb: "run",
44-
Name: name,
45-
Visibility: privateExecVisibility(),
46-
Description: docstring,
32+
Verb: "run",
33+
Name: name,
34+
Visibility: privateExecVisibility(),
4735
Request: &executable.RequestExecutableType{
4836
URL: "https://httpbin.org/post",
4937
Method: "POST",
@@ -59,13 +47,10 @@ func RequestExecWithBody(opts ...Option) *executable.Executable {
5947

6048
func RequestExecWithTransform(opts ...Option) *executable.Executable {
6149
name := "request-with-transform"
62-
docstring := requestBaseDesc +
63-
"The `transformResponse` field is optional and can be used to transform the response using an Expr expression."
6450
e := &executable.Executable{
65-
Verb: "run",
66-
Name: name,
67-
Visibility: privateExecVisibility(),
68-
Description: docstring,
51+
Verb: "run",
52+
Name: name,
53+
Visibility: privateExecVisibility(),
6954
Request: &executable.RequestExecutableType{
7055
URL: "https://httpbin.org/get",
7156
TransformResponse: "status",
@@ -81,13 +66,10 @@ func RequestExecWithTransform(opts ...Option) *executable.Executable {
8166

8267
func RequestExecWithTimeout(opts ...Option) *executable.Executable {
8368
name := "request-with-timeout"
84-
docstring := requestBaseDesc +
85-
"The `timeout` field is optional and can be used to set the request timeout."
8669
e := &executable.Executable{
87-
Verb: "run",
88-
Name: name,
89-
Visibility: privateExecVisibility(),
90-
Description: docstring,
70+
Verb: "run",
71+
Name: name,
72+
Visibility: privateExecVisibility(),
9173
Request: &executable.RequestExecutableType{
9274
URL: "https://httpbin.org/delay/3",
9375
Timeout: 1,
@@ -102,14 +84,10 @@ func RequestExecWithTimeout(opts ...Option) *executable.Executable {
10284

10385
func RequestExecWithValidatedStatus(opts ...Option) *executable.Executable {
10486
name := "request-with-validated-status"
105-
docstring := requestBaseDesc +
106-
"The `validStatusCodes` field is optional and can be used to specify the valid status codes. " +
107-
"If the response status code is not in the list, the executable will fail."
10887
e := &executable.Executable{
109-
Verb: "run",
110-
Name: name,
111-
Visibility: privateExecVisibility(),
112-
Description: docstring,
88+
Verb: "run",
89+
Name: name,
90+
Visibility: privateExecVisibility(),
11391
Request: &executable.RequestExecutableType{
11492
URL: "https://httpbin.org/status/400",
11593
ValidStatusCodes: []int{200},
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import (
44
"github.com/flowexec/flow/types/executable"
55
)
66

7-
const (
8-
serialBaseDesc = "Multiple executables can be run in sequence using a serial executable.\n"
9-
)
10-
117
func SerialExecByRefConfig(opts ...Option) *executable.Executable {
128
name := "serial-config"
139
e1 := SimpleExec(opts...)
@@ -16,9 +12,6 @@ func SerialExecByRefConfig(opts ...Option) *executable.Executable {
1612
Verb: "start",
1713
Name: name,
1814
Visibility: privateExecVisibility(),
19-
Description: serialBaseDesc +
20-
"The `execs` field can be used to define the child executables with more options. " +
21-
"This includes defining an executable inline, retries, arguments, and more.",
2215
Serial: &executable.SerialExecutableType{
2316
Execs: []executable.SerialRefConfig{
2417
{Ref: e1.Ref()},
@@ -45,8 +38,6 @@ func SerialExecWithExit(opts ...Option) *executable.Executable {
4538
Name: name,
4639
Aliases: []string{"serial-exit"},
4740
Visibility: privateExecVisibility(),
48-
Description: serialBaseDesc +
49-
"The `failFast` option can be set to `true` to stop the executable if a sub-executable fails.",
5041
Serial: &executable.SerialExecutableType{
5142
FailFast: &ff,
5243
Execs: []executable.SerialRefConfig{{Ref: e1.Ref()}, {Ref: e2.Ref()}, {Ref: e3.Ref()}},

tests/utils/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/flowexec/flow/internal/logger"
2323
"github.com/flowexec/flow/internal/runner/mocks"
2424
"github.com/flowexec/flow/internal/services/store"
25-
"github.com/flowexec/flow/tools/builder"
25+
"github.com/flowexec/flow/tests/utils/builder"
2626
"github.com/flowexec/flow/types/config"
2727
"github.com/flowexec/flow/types/workspace"
2828
)

0 commit comments

Comments
 (0)