Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Dominic Della Valle <[email protected]>
  • Loading branch information
djdv committed Apr 25, 2018
1 parent b106920 commit 4160477
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cli/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -518,3 +519,40 @@ func TestBodyArgs(t *testing.T) {
}
}
}

func TestLinkArgs(t *testing.T) {
root, err := ioutil.TempDir("", "cmds-link-test")
if err != nil {
t.Fatalf("cannot create symlink test root: %v", err)
}
defer os.RemoveAll(root)

realDir := filepath.Join(root, "RealDir")
dirLink := filepath.Join(root, "DirLink")
os.Mkdir(realDir, 0755)
err = os.Symlink(realDir, dirLink)
if err != nil {
t.Fatalf("cannot create symlink %q->%q: %v", dirLink, realDir, err)
}

dirArgs := &cmdkit.Argument{Type: cmdkit.ArgFile, Recursive: true}
linkArgs := &cmdkit.Argument{Type: cmdkit.ArgFile}

ld, err := appendFile(realDir, dirArgs, true, true, true)
if err != nil {
t.Fatalf("cannot append directory %q: %v", realDir, err)
}

if !ld.IsDirectory() {
t.Fatalf("symlink was not resolved when intended")
}

ld, err = appendFile(dirLink, linkArgs, true, true, false)
if err != nil {
t.Fatalf("cannot append link %q: %v", dirLink, err)
}

if ld.IsDirectory() {
t.Fatalf("symlink was resolved when not intended")
}
}

0 comments on commit 4160477

Please sign in to comment.