summaryrefslogtreecommitdiffstats
path: root/helpers/path_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/path_test.go')
-rw-r--r--helpers/path_test.go65
1 files changed, 25 insertions, 40 deletions
diff --git a/helpers/path_test.go b/helpers/path_test.go
index 98291936c..e58a045c1 100644
--- a/helpers/path_test.go
+++ b/helpers/path_test.go
@@ -29,8 +29,6 @@ import (
"github.com/stretchr/testify/require"
- "github.com/stretchr/testify/assert"
-
"github.com/gohugoio/hugo/hugofs"
"github.com/spf13/afero"
"github.com/spf13/viper"
@@ -73,18 +71,9 @@ func TestMakePath(t *testing.T) {
}
func TestMakePathSanitized(t *testing.T) {
- v := viper.New()
- v.Set("contentDir", "content")
- v.Set("dataDir", "data")
- v.Set("i18nDir", "i18n")
- v.Set("layoutDir", "layouts")
- v.Set("assetDir", "assets")
- v.Set("resourceDir", "resources")
- v.Set("publishDir", "public")
- v.Set("archetypeDir", "archetypes")
+ v := newTestCfg()
- l := langs.NewDefaultLanguage(v)
- p, _ := NewPathSpec(hugofs.NewMem(v), l)
+ p, _ := NewPathSpec(hugofs.NewMem(v), v)
tests := []struct {
input string
@@ -166,33 +155,6 @@ func TestGetRelativePath(t *testing.T) {
}
}
-func TestGetRealPath(t *testing.T) {
- if runtime.GOOS == "windows" && os.Getenv("CI") == "" {
- t.Skip("Skip TestGetRealPath as os.Symlink needs administrator rights on Windows")
- }
-
- d1, _ := ioutil.TempDir("", "d1")
- defer os.Remove(d1)
- fs := afero.NewOsFs()
-
- rp1, err := GetRealPath(fs, d1)
- require.NoError(t, err)
- assert.Equal(t, d1, rp1)
-
- sym := filepath.Join(os.TempDir(), "d1sym")
- err = os.Symlink(d1, sym)
- require.NoError(t, err)
- defer os.Remove(sym)
-
- rp2, err := GetRealPath(fs, sym)
- require.NoError(t, err)
-
- // On OS X, the temp folder is itself a symbolic link (to /private...)
- // This has to do for now.
- assert.True(t, strings.HasSuffix(rp2, d1))
-
-}
-
func TestMakePathRelative(t *testing.T) {
type test struct {
inPath, path1, path2, output string
@@ -659,6 +621,29 @@ func TestPrettifyPath(t *testing.T) {
}
+func TestExtractAndGroupRootPaths(t *testing.T) {
+ in := []string{
+ filepath.FromSlash("/a/b/c/d"),
+ filepath.FromSlash("/a/b/c/e"),
+ filepath.FromSlash("/a/b/e/f"),
+ filepath.FromSlash("/a/b"),
+ filepath.FromSlash("/a/b/c/b/g"),
+ filepath.FromSlash("/c/d/e"),
+ }
+
+ inCopy := make([]string, len(in))
+ copy(inCopy, in)
+
+ result := ExtractAndGroupRootPaths(in)
+
+ assert := require.New(t)
+ assert.Equal(filepath.FromSlash("[/a/b/{c,e} /c/d/e]"), fmt.Sprint(result))
+
+ // Make sure the original is preserved
+ assert.Equal(inCopy, in)
+
+}
+
func TestExtractRootPaths(t *testing.T) {
tests := []struct {
input []string