daria-malkova commented on a change in pull request #16374:
URL: https://github.com/apache/beam/pull/16374#discussion_r782776329



##########
File path: playground/backend/internal/fs_tool/fs_test.go
##########
@@ -30,132 +28,108 @@ import (
 const (
        sourceDir       = "sourceDir"
        destinationDir  = "destinationDir"
+       testFileMode    = 0755
        pipelinesFolder = "executable_files"
 )
 
-func TestMain(m *testing.M) {
-       err := setupPreparedFiles()
-       if err != nil {
-               logger.Fatal(err)
-       }
-       defer teardown()
-       m.Run()
-}
-
-func setupPreparedFiles() error {
-       err := os.Mkdir(sourceDir, 0755)
+func prepareFiles() error {
+       err := os.Mkdir(sourceDir, testFileMode)
        if err != nil {
                return err
        }
-       err = os.Mkdir(destinationDir, 0755)
+       err = os.Mkdir(destinationDir, testFileMode)
        if err != nil {
                return err
        }
        filePath := filepath.Join(sourceDir, "file.txt")
        _, err = os.Create(filePath)
-       if err != nil {
-               return err
-       }
-       return nil
+       return err
 }
 
-func teardown() {
+func teardownFiles() error {
        err := os.RemoveAll(sourceDir)
        if err != nil {
-               logger.Fatal(err)
-       }
-       err = os.RemoveAll(destinationDir)
-       if err != nil {
-               logger.Fatal(err)
-       }
-       err = os.RemoveAll(pipelinesFolder)
-       if err != nil {
-               logger.Fatal(err)
+               return err
        }
+       return os.RemoveAll(destinationDir)
 }
 
-func TestLifeCycle_CreateExecutableFile(t *testing.T) {
-       pipelineId := uuid.New()
-       baseFileFolder := fmt.Sprintf("%s/%s", pipelinesFolder, pipelineId)
-       srcFileFolder := baseFileFolder + "/src"
-       binFileFolder := baseFileFolder + "/bin"
+func prepareFolders(baseFileFolder string) error {
+       srcFileFolder := filepath.Join(baseFileFolder, "src")
+
+       return os.MkdirAll(srcFileFolder, testFileMode)
+}
+
+func teardownFolders(baseFileFolder string) error {

Review comment:
       Why have you divided teardown to two methods? 

##########
File path: playground/backend/internal/fs_tool/fs.go
##########
@@ -92,26 +86,17 @@ func (l *LifeCycle) DeleteFolders() error {
 }
 
 // CreateSourceCodeFile creates an executable file (i.e. 
file.{sourceFileExtension}).
-func (l *LifeCycle) CreateSourceCodeFile(code string) (string, error) {
-       if _, err := os.Stat(l.Folder.SourceFileFolder); os.IsNotExist(err) {
-               return "", err
+func (l *LifeCycle) CreateSourceCodeFile(code string) error {
+       if _, err := os.Stat(l.Paths.AbsoluteSourceFileFolderPath); 
os.IsNotExist(err) {
+               return err
        }
 
-       fileName := l.pipelineId.String() + l.Extension.SourceFileExtension
-       filePath := filepath.Join(l.Folder.SourceFileFolder, fileName)
+       filePath := l.Paths.AbsoluteSourceFilePath

Review comment:
       Can we use _lc_ instead of _l_? To make it equal everywhere? 

##########
File path: playground/backend/internal/fs_tool/fs_test.go
##########
@@ -30,132 +28,108 @@ import (
 const (
        sourceDir       = "sourceDir"
        destinationDir  = "destinationDir"
+       testFileMode    = 0755
        pipelinesFolder = "executable_files"
 )
 
-func TestMain(m *testing.M) {
-       err := setupPreparedFiles()
-       if err != nil {
-               logger.Fatal(err)
-       }
-       defer teardown()
-       m.Run()
-}
-
-func setupPreparedFiles() error {
-       err := os.Mkdir(sourceDir, 0755)
+func prepareFiles() error {
+       err := os.Mkdir(sourceDir, testFileMode)
        if err != nil {
                return err
        }
-       err = os.Mkdir(destinationDir, 0755)
+       err = os.Mkdir(destinationDir, testFileMode)
        if err != nil {
                return err
        }
        filePath := filepath.Join(sourceDir, "file.txt")
        _, err = os.Create(filePath)
-       if err != nil {
-               return err
-       }
-       return nil
+       return err
 }
 
-func teardown() {
+func teardownFiles() error {

Review comment:
       Why have you decided to change the method name? _teardown_ is common 
name 

##########
File path: playground/backend/internal/fs_tool/lc_constructor.go
##########
@@ -30,35 +30,51 @@ func newCompilingLifeCycle(pipelineId uuid.UUID, 
pipelinesFolder, sourceFileExte
        baseFileFolder := filepath.Join(pipelinesFolder, pipelineId.String())
        srcFileFolder := filepath.Join(baseFileFolder, sourceFolderName)
        binFileFolder := filepath.Join(baseFileFolder, compiledFolderName)
+
+       srcFileName := pipelineId.String() + sourceFileExtension
+       absSrcFileFolderPath, _ := filepath.Abs(srcFileFolder)
+       absSrcFilePath, _ := filepath.Abs(filepath.Join(absSrcFileFolderPath, 
srcFileName))

Review comment:
       Don't you need to process errors somehow? 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to