github.com/hoffie/larasync@v0.0.0-20151025221940-0384d2bddcef/helpers/path/path_test.go (about)

     1  package path
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"strings"
     7  
     8  	. "gopkg.in/check.v1"
     9  )
    10  
    11  var _ = Suite(&PathTests{})
    12  
    13  type PathTests struct {
    14  	oldDir string
    15  	dir    string
    16  }
    17  
    18  func (t *PathTests) SetUpTest(c *C) {
    19  	var err error
    20  	t.oldDir, err = os.Getwd()
    21  	c.Assert(err, IsNil)
    22  	// Fix for OSX systems. Temporary folder lies in a symlink directory
    23  	// /var/folders which is actually at /private/var/folders
    24  	t.dir, err = filepath.EvalSymlinks(c.MkDir())
    25  	c.Assert(err, IsNil)
    26  	err = os.Chdir(t.dir)
    27  	c.Assert(err, IsNil)
    28  }
    29  
    30  func (t *PathTests) TearDownTest(c *C) {
    31  	os.Chdir(t.oldDir)
    32  }
    33  
    34  func (t *PathTests) TestNormalizeAbs(c *C) {
    35  	err := os.Chdir(filepath.Join(t.dir, ".."))
    36  	c.Assert(err, IsNil)
    37  	base := filepath.Base(t.dir)
    38  	n, err := Normalize(base)
    39  	c.Assert(err, IsNil)
    40  	c.Assert(n, Equals, t.dir)
    41  }
    42  
    43  func (t *PathTests) TestNormalizeRedundantChar(c *C) {
    44  	path := strings.Replace(t.dir, string(filepath.Separator),
    45  		string(filepath.Separator)+string(filepath.Separator), -1)
    46  	c.Assert(path, Not(Equals), t.dir)
    47  	n, err := Normalize(path)
    48  	c.Assert(err, IsNil)
    49  	c.Assert(n, Equals, t.dir)
    50  }
    51  
    52  func (t *PathTests) TestIsBelow(c *C) {
    53  	basePath := t.dir
    54  	belowPath := filepath.Dir(t.dir)
    55  
    56  	is, err := IsBelow(basePath, belowPath)
    57  	c.Assert(err, IsNil)
    58  	c.Assert(is, Equals, true)
    59  }