Skip to content

Commit

Permalink
fix(worker): affero junit
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault authored and richardlt committed Jan 17, 2020
1 parent 9512ea2 commit c4335ab
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions engine/worker/internal/action/builtin_junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"encoding/xml"
"errors"
"fmt"
"io/ioutil"
"path/filepath"
"strings"

"github.com/spf13/afero"

"github.com/ovh/cds/engine/worker/pkg/workerruntime"
"github.com/ovh/cds/sdk"
Expand All @@ -27,7 +28,24 @@ func RunParseJunitTestResultAction(ctx context.Context, wk workerruntime.Runtime
return res, errors.New("UnitTest parser: path not provided")
}

files, errg := filepath.Glob(p)
workdir, err := workerruntime.WorkingDirectory(ctx)
if err != nil {
return res, err
}

var abs string
if x, ok := wk.BaseDir().(*afero.BasePathFs); ok {
abs, _ = x.RealPath(workdir.Name())
} else {
abs = workdir.Name()
}

wkDirFS := afero.NewBasePathFs(afero.NewOsFs(), abs)
path := strings.TrimPrefix(p, abs)

// Global all files matching filePath
files, errg := afero.Glob(wkDirFS, path)

if errg != nil {
return res, errors.New("UnitTest parser: Cannot find requested files, invalid pattern")
}
Expand All @@ -38,7 +56,7 @@ func RunParseJunitTestResultAction(ctx context.Context, wk workerruntime.Runtime
for _, f := range files {
var ftests venom.Tests

data, errRead := ioutil.ReadFile(f)
data, errRead := afero.ReadFile(wkDirFS, f)
if errRead != nil {
return res, fmt.Errorf("UnitTest parser: cannot read file %s (%s)", f, errRead)
}
Expand All @@ -61,7 +79,7 @@ func RunParseJunitTestResultAction(ctx context.Context, wk workerruntime.Runtime
wk.SendLog(ctx, workerruntime.LevelInfo, r)
}

if err := wk.Blur(tests); err != nil {
if err := wk.Blur(&tests); err != nil {
return res, err
}

Expand Down

0 comments on commit c4335ab

Please sign in to comment.