1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
package smb2
import (
"testing"
)
var testBase = []struct {
Path string
Base string
}{
{"", ""},
{`\`, ""},
{`\foo`, "foo"},
{`\foo\bar`, "bar"},
{`foo\bar`, "bar"},
{`foo\bar\`, "bar"},
{`foo\bar\\`, "bar"},
{`foo`, "foo"},
}
func TestBase(t *testing.T) {
for _, c := range testBase {
if base(c.Path) != c.Base {
t.Errorf("path: %v, expected: %v, got: %v", c.Path, c.Base, base(c.Path))
}
}
}
var testDir = []struct {
Path string
Dir string
}{
{"", ""},
{`\`, `\`},
{`\foo`, `\`},
{`\foo\bar`, `\foo`},
{`foo\bar`, "foo"},
{`foo\bar\`, "foo"},
{`foo\bar\\`, "foo"},
{`foo`, ""},
}
func TestDir(t *testing.T) {
for _, c := range testDir {
if dir(c.Path) != c.Dir {
t.Errorf("path: %v, expected: %v, got: %v", c.Path, c.Dir, base(c.Path))
}
}
}
var testMountPath = []struct {
Path string
Ok bool
}{
{`\\server\share`, true},
{`\\server\share\`, false},
{`\\server\share\file`, false},
{`\\127.0.0.1\share`, true},
{`\\[0:0:0:0:0:0:0:1]\share`, true},
}
func TestValidateMountPath(t *testing.T) {
for _, c := range testMountPath {
if err := validateMountPath(c.Path); err == nil != c.Ok {
t.Errorf("path: %v, expected: %v, got: %v", c.Path, c.Ok, err == nil)
}
}
}
|