Skip to content

Commit

Permalink
fix path import
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu Frenette <[email protected]>
  • Loading branch information
silphid committed Mar 6, 2021
2 parents 363bfb9 + 3102509 commit c15c9d5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/internal/evaluation/getEntries_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package evaluation

import (
"path"
"path/filepath"
"sort"
"testing"

Expand Down Expand Up @@ -173,8 +173,8 @@ func TestGetEntries(t *testing.T) {
var results []entry
for _, ent := range entries {
results = append(results, entry{
input: path.Join(inputDir, ent.input),
output: path.Join("/output", ent.output),
input: filepath.Join(inputDir, ent.input),
output: filepath.Join("/output", ent.output),
render: ent.render,
})
}
Expand All @@ -188,7 +188,7 @@ func TestGetEntries(t *testing.T) {
defer removeAll(inputDir)

for _, file := range f.Files {
inputFile := path.Join(inputDir, file)
inputFile := filepath.Join(inputDir, file)
createEmptyFile(inputFile)
}

Expand Down
11 changes: 6 additions & 5 deletions src/internal/evaluation/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package evaluation

import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io/ioutil"
"os"
"path"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func getTempDir() string {
Expand Down Expand Up @@ -56,7 +57,7 @@ func deleteFile(file string) {
}

func createEmptyFile(filePath string) {
dir := path.Dir(filePath)
dir := filepath.Dir(filePath)
err := os.MkdirAll(dir, os.ModePerm)
if err != nil {
panic(err)
Expand All @@ -80,7 +81,7 @@ func compareDirsRecursively(t *testing.T, expectedDir, actualDir string) {
require.Equal(t, expectedInfo.IsDir(), actualInfo.IsDir(), "is directory must match")

if expectedInfo.IsDir() {
compareDirsRecursively(t, path.Join(expectedDir, expectedInfo.Name()), path.Join(actualDir, actualInfo.Name()))
compareDirsRecursively(t, filepath.Join(expectedDir, expectedInfo.Name()), filepath.Join(actualDir, actualInfo.Name()))
}
}
}
8 changes: 4 additions & 4 deletions src/internal/evaluation/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"

"github.com/Samasource/jen/src/internal/logging"
)
Expand Down Expand Up @@ -47,12 +47,12 @@ func getEntries(context Context, inputDir, outputDir string, renderParent bool)
for _, info := range infos {
// Determine input/output names and render mode
inputName := info.Name()
inputPath := path.Join(inputDir, inputName)
inputPath := filepath.Join(inputDir, inputName)
outputName, included, renderMode, err := evalFileName(context, inputName)
if err != nil {
return nil, err
}
outputPath := path.Join(outputDir, outputName)
outputPath := filepath.Join(outputDir, outputName)

// Determine render enabled/disabled for this item
renderItem := renderParent
Expand Down Expand Up @@ -104,7 +104,7 @@ func renderFile(context Context, inputPath, outputPath string, render bool) erro
}

// Create output dir
outputDir := path.Dir(outputPath)
outputDir := filepath.Dir(outputPath)
err = os.MkdirAll(outputDir, os.ModePerm)
if err != nil {
return fmt.Errorf("failed to create output directory %q: %w", outputDir, err)
Expand Down
6 changes: 3 additions & 3 deletions src/internal/evaluation/render_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package evaluation

import (
"path"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -28,9 +28,9 @@ func TestRender(t *testing.T) {
t.Run(name, func(t *testing.T) {
outputDir := getTempDir()
defer removeAll(outputDir)
err := Render(context, path.Join("testdata", name, "input"), outputDir)
err := Render(context, filepath.Join("testdata", name, "input"), outputDir)
assert.NoError(t, err)
compareDirsRecursively(t, path.Join("testdata", name, "output"), outputDir)
compareDirsRecursively(t, filepath.Join("testdata", name, "output"), outputDir)
})
}
}
9 changes: 4 additions & 5 deletions src/internal/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -55,8 +54,8 @@ func (p Project) Save() error {
return err
}

filePath := path.Join(p.Dir, constant.ProjectFileName)
return ioutil.WriteFile(filePath, doc, os.ModePerm)
path := filepath.Join(p.Dir, constant.ProjectFileName)
return ioutil.WriteFile(path, doc, os.ModePerm)
}

// Load loads the project file from given project directory
Expand Down Expand Up @@ -178,7 +177,7 @@ func promptTemplate(templatesDir string) (string, error) {
if strings.HasPrefix(template, ".") {
continue
}
templateDir := path.Join(templatesDir, template)
templateDir := filepath.Join(templatesDir, template)
spec, err := spec.Load(templateDir)
if err != nil {
return "", err
Expand Down Expand Up @@ -211,5 +210,5 @@ func (p Project) GetTemplateDir() (string, error) {
if err != nil {
return "", err
}
return path.Join(templatesDir, p.TemplateName), nil
return filepath.Join(templatesDir, p.TemplateName), nil
}
8 changes: 4 additions & 4 deletions src/internal/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package spec

import (
"fmt"
"path"
"path/filepath"

"github.com/Samasource/jen/src/internal/constant"
"github.com/Samasource/jen/src/internal/exec"
Expand All @@ -27,7 +27,7 @@ type Spec struct {

// Load loads spec object from a template directory
func Load(templateDir string) (*Spec, error) {
specFilePath := path.Join(templateDir, constant.SpecFileName)
specFilePath := filepath.Join(templateDir, constant.SpecFileName)
yamlFile, err := yaml.ReadFile(specFilePath)
if err != nil {
return nil, err
Expand All @@ -44,7 +44,7 @@ func loadFromMap(_map yaml.Map, templateDir string) (*Spec, error) {
spec := new(Spec)

// Load metadata
spec.Name = path.Base(templateDir)
spec.Name = filepath.Base(templateDir)
var err error
spec.Version, err = getRequiredStringFromMap(_map, "version")
if err != nil {
Expand Down Expand Up @@ -322,7 +322,7 @@ func loadRenderStep(_map yaml.Map, templateDir string) (exec.Executable, error)
}

return render.Render{
InputDir: path.Join(templateDir, source),
InputDir: filepath.Join(templateDir, source),
}, nil
}

Expand Down

0 comments on commit c15c9d5

Please sign in to comment.