Skip to content

Commit

Permalink
fix(worker): coverage action
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin authored and richardlt committed Jan 17, 2020
1 parent cc5a873 commit 212d5b3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
19 changes: 14 additions & 5 deletions engine/worker/internal/action/builtin_coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package action
import (
"context"
"fmt"
"path"
"path/filepath"
"strconv"
"strings"

coverage "github.com/sguiheux/go-coverage"
"github.com/spf13/afero"
Expand Down Expand Up @@ -55,13 +55,22 @@ func RunParseCoverageResultAction(ctx context.Context, wk workerruntime.Runtime,
if err != nil {
return res, err
}
var dir string

var fpath string
var abs string
if x, ok := wk.BaseDir().(*afero.BasePathFs); ok {
dir, _ = x.RealPath(workdir.Name())
abs, _ = x.RealPath(workdir.Name())
} else {
dir = workdir.Name()
abs = workdir.Name()
}
parser := coverage.New(filepath.Join(dir, strings.TrimPrefix(p, dir)), parserMode)

if !path.IsAbs(p) {
fpath = filepath.Join(abs, p)
} else {
fpath = p
}

parser := coverage.New(fpath, parserMode)
report, errR := parser.Parse()
if errR != nil {
return res, fmt.Errorf("coverage parser: unable to parse report: %v", errR)
Expand Down
20 changes: 16 additions & 4 deletions engine/worker/internal/action/builtin_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package action
import (
"bytes"
"encoding/json"
"github.com/ovh/cds/sdk/cdsclient"
"github.com/stretchr/testify/require"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"

"github.com/ovh/cds/sdk/cdsclient"
"github.com/stretchr/testify/require"

"github.com/sguiheux/go-coverage"
"gopkg.in/h2non/gock.v1"

Expand Down Expand Up @@ -47,6 +49,11 @@ func TestRunCoverage(t *testing.T) {
wk, ctx := setupTest(t)
assert.NoError(t, ioutil.WriteFile("results.xml", []byte(cobertura_result), os.ModePerm))

fi, err := os.Open("results.xml")
require.NoError(t, err)
fiPath, err := filepath.Abs(fi.Name())
require.NoError(t, err)

gock.New("http://lolcat.host").Post("/queue/workflows/666/coverage").
Reply(200)

Expand Down Expand Up @@ -78,7 +85,7 @@ func TestRunCoverage(t *testing.T) {
Parameters: []sdk.Parameter{
{
Name: "path",
Value: "./results.xml",
Value: fiPath,
},
{
Name: "format",
Expand All @@ -100,6 +107,11 @@ func TestRunCoverageMinimumFail(t *testing.T) {
wk, ctx := setupTest(t)
assert.NoError(t, ioutil.WriteFile("results.xml", []byte(cobertura_result), os.ModePerm))

fi, err := os.Open("results.xml")
require.NoError(t, err)
fiPath, err := filepath.Abs(fi.Name())
require.NoError(t, err)

gock.New("http://lolcat.host").Post("/queue/workflows/666/coverage").
Reply(200)

Expand Down Expand Up @@ -131,7 +143,7 @@ func TestRunCoverageMinimumFail(t *testing.T) {
Parameters: []sdk.Parameter{
{
Name: "path",
Value: "./results.xml",
Value: fiPath,
},
{
Name: "format",
Expand Down

0 comments on commit 212d5b3

Please sign in to comment.