-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[BEAM-13343][Playground] Support go unit tests #16138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9cc287e
6c87b92
a8ca785
d1b5af7
60f91d6
82b8c0c
85120af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| { | ||
| "compile_cmd": "go", | ||
| "run_cmd": "", | ||
| "test_cmd": "go", | ||
| "compile_args": [ | ||
| "build", | ||
| "-o", | ||
| "bin" | ||
| ], | ||
| "run_args": [ | ||
| ], | ||
| "test_args": [ | ||
| "test", | ||
| "-v" | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -69,7 +69,7 @@ func Process(ctx context.Context, cacheService cache.Cache, lc *fs_tool.LifeCycl | |||||
|
|
||||||
| go cancelCheck(ctxWithTimeout, pipelineId, cancelChannel, cacheService) | ||||||
|
|
||||||
| executorBuilder, err := builder.SetupExecutorBuilder(lc.GetAbsoluteSourceFilePath(), lc.GetAbsoluteBaseFolderPath(), lc.GetAbsoluteExecutableFilePath(), utils.ReduceWhiteSpacesToSinge(pipelineOptions), sdkEnv) | ||||||
| executorBuilder, err := builder.SetupExecutorBuilder(lc, utils.ReduceWhiteSpacesToSinge(pipelineOptions), sdkEnv) | ||||||
| if err != nil { | ||||||
| _ = processSetupError(err, pipelineId, cacheService, ctxWithTimeout) | ||||||
| return | ||||||
|
|
@@ -88,14 +88,20 @@ func Process(ctx context.Context, cacheService cache.Cache, lc *fs_tool.LifeCycl | |||||
| _ = processError(ctxWithTimeout, errorChannel, pipelineId, cacheService, "Validate", pb.Status_STATUS_VALIDATION_ERROR) | ||||||
| return | ||||||
| } | ||||||
| // Check if unit test | ||||||
| isUnitTest := false | ||||||
| valResult, ok := validationResults.Load(validators.UnitTestValidatorName) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| if ok && valResult.(bool) { | ||||||
| isUnitTest = true | ||||||
| } | ||||||
|
Comment on lines
+91
to
+96
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe wrap it like a separate method? |
||||||
| if err := processSuccess(ctxWithTimeout, pipelineId, cacheService, "Validate", pb.Status_STATUS_PREPARING); err != nil { | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| // Prepare | ||||||
| logger.Infof("%s: Prepare() ...\n", pipelineId) | ||||||
| prepareFunc := executor.Prepare() | ||||||
| go prepareFunc(successChannel, errorChannel) | ||||||
| go prepareFunc(successChannel, errorChannel, isUnitTest) | ||||||
|
|
||||||
| ok, err = processStep(ctxWithTimeout, pipelineId, cacheService, cancelChannel, successChannel) | ||||||
| if err != nil { | ||||||
|
|
@@ -111,24 +117,31 @@ func Process(ctx context.Context, cacheService cache.Cache, lc *fs_tool.LifeCycl | |||||
|
|
||||||
| switch sdkEnv.ApacheBeamSdk { | ||||||
| case pb.Sdk_SDK_JAVA, pb.Sdk_SDK_GO: | ||||||
| // Compile | ||||||
| logger.Infof("%s: Compile() ...\n", pipelineId) | ||||||
| compileCmd := executor.Compile(ctxWithTimeout) | ||||||
| var compileError bytes.Buffer | ||||||
| var compileOutput bytes.Buffer | ||||||
| runCmdWithOutput(compileCmd, &compileOutput, &compileError, successChannel, errorChannel) | ||||||
|
|
||||||
| ok, err = processStep(ctxWithTimeout, pipelineId, cacheService, cancelChannel, successChannel) | ||||||
| if err != nil { | ||||||
| return | ||||||
| } | ||||||
| if !ok { | ||||||
| _ = processCompileError(ctxWithTimeout, errorChannel, compileError.Bytes(), pipelineId, cacheService) | ||||||
| return | ||||||
| } | ||||||
| if err := processCompileSuccess(ctxWithTimeout, compileOutput.Bytes(), pipelineId, cacheService); err != nil { | ||||||
| return | ||||||
| if sdkEnv.ApacheBeamSdk == pb.Sdk_SDK_GO && isUnitTest { | ||||||
| if err := processCompileSuccess(ctxWithTimeout, []byte(""), pipelineId, cacheService); err != nil { | ||||||
| return | ||||||
| } | ||||||
| } else { | ||||||
| // Compile | ||||||
| logger.Infof("%s: Compile() ...\n", pipelineId) | ||||||
| compileCmd := executor.Compile(ctxWithTimeout) | ||||||
| var compileError bytes.Buffer | ||||||
| var compileOutput bytes.Buffer | ||||||
| runCmdWithOutput(compileCmd, &compileOutput, &compileError, successChannel, errorChannel) | ||||||
|
|
||||||
| ok, err = processStep(ctxWithTimeout, pipelineId, cacheService, cancelChannel, successChannel) | ||||||
| if err != nil { | ||||||
| return | ||||||
| } | ||||||
| if !ok { | ||||||
| _ = processCompileError(ctxWithTimeout, errorChannel, compileError.Bytes(), pipelineId, cacheService) | ||||||
| return | ||||||
| } | ||||||
| if err := processCompileSuccess(ctxWithTimeout, compileOutput.Bytes(), pipelineId, cacheService); err != nil { | ||||||
| return | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| case pb.Sdk_SDK_PYTHON: | ||||||
| if err := processCompileSuccess(ctxWithTimeout, []byte(""), pipelineId, cacheService); err != nil { | ||||||
| return | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,31 +17,51 @@ package preparators | |
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strings" | ||
| ) | ||
|
|
||
| const ( | ||
| nameBinGo = "go" | ||
| fmtArgs = "fmt" | ||
| goName = "go" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe |
||
| fmtArgs = "fmt" | ||
| mvCmd = "mv" | ||
| sep = "." | ||
| ) | ||
|
|
||
| // GetGoPreparators returns reparation methods that should be applied to Go code | ||
| func GetGoPreparators(filePath string) *[]Preparator { | ||
| preparatorArgs := make([]interface{}, 1) | ||
| preparatorArgs[0] = filePath | ||
| formatCodePreparator := Preparator{Prepare: formatCode, Args: preparatorArgs} | ||
| return &[]Preparator{formatCodePreparator} | ||
| changeNamePreparator := Preparator{Prepare: changeFileName, Args: preparatorArgs} | ||
| return &[]Preparator{formatCodePreparator, changeNamePreparator} | ||
| } | ||
|
|
||
| // formatCode formats go code | ||
| func formatCode(args ...interface{}) error { | ||
| filePath := args[0].(string) | ||
| cmd := exec.Command(nameBinGo, fmtArgs, filepath.Base(filePath)) | ||
| cmd := exec.Command(goName, fmtArgs, filepath.Base(filePath)) | ||
| cmd.Dir = filepath.Dir(filePath) | ||
| stdout, err := cmd.CombinedOutput() | ||
| if err != nil { | ||
| return errors.New(string(stdout)) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func changeFileName(args ...interface{}) error { | ||
| filePath := args[0].(string) | ||
| isUnitTest := args[1].(bool) | ||
| if isUnitTest { | ||
| testFileName := fmt.Sprintf("%s_test.%s", strings.Split(filePath, sep)[0], goName) | ||
| cmd := exec.Command(mvCmd, filePath, testFileName) | ||
| fmt.Println(cmd.String()) | ||
| stdout, err := cmd.CombinedOutput() | ||
| if err != nil { | ||
| return errors.New(string(stdout)) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add an empty string.