Skip to content

Commit

Permalink
test: add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
hirochachacha committed Feb 16, 2020
1 parent 62da742 commit 0e82d26
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -26,4 +26,4 @@ _testmain.go
*.test
*.prof

.client_test.conf.json
/client_conf.json
19 changes: 15 additions & 4 deletions .travis.yml
@@ -1,7 +1,18 @@
language: go
go:
- 1.5
- 1.6
- tip
- 1.12
- 1.13
- tip
os:
- linux
addons:
apt:
packages:
- samba
before_install:
- cp .travis/client_conf.json ./
- sudo cp .travis/smb.conf /etc/samba/smb.conf
- (echo travis; echo travis) | sudo smbpasswd -a -s travis
- sudo smbd
script:
- go test -v -race ./...
- go test -v -race ./...
11 changes: 4 additions & 7 deletions .client_test.conf.json.tmpl → .travis/client_conf.json
@@ -1,7 +1,7 @@
{
"transport": {
"type": "tcp",
"host": "192.168.0.8",
"host": "localhost",
"port": 445
},
"conn": {
Expand All @@ -12,13 +12,10 @@
},
"session": {
"type": "ntlm",
"user": "Guest",
"passwd": "",
"domain": "MicrosoftAccount",
"workstation": "fakerune.local",
"targetSPN": "cifs/192.168.0.8"
"user": "travis",
"passwd": "travis"
},
"tree_conn": {
"share": "\\\\192.168.0.8\\work"
"share": "\\\\localhost\\tmp"
}
}
3 changes: 3 additions & 0 deletions .travis/smb.conf
@@ -0,0 +1,3 @@
[tmp]
path = /tmp
read only = no
21 changes: 9 additions & 12 deletions client.go
Expand Up @@ -324,12 +324,14 @@ func (fs *RemoteFileSystem) Rename(oldpath, newpath string) error {
}

// Symlink mimics os.Symlink.
// There is a restriction about target pathname.
// This API should work on latest Windows and latest MacOS.
// However it may not work on Linux because Samba doesn't support reparse point well.
// Also there is a restriction on target pathname.
// Generally, a pathname begins with leading backslash (e.g `\dir\name`) can be interpreted as two ways.
// In windows, it is evaluated as a relative path, in other systems, it is evaluated as an absolute path.
// On windows, it is evaluated as a relative path, on other systems, it is evaluated as an absolute path.
// This implementation always assumes that format is absolute path.
// So, if you know the server is windows, you should avoid that format.
// If you want to use an absolute target path on windows, you can use `C:\dir\name` format.
// So, if you know the target server is Windows, you should avoid that format.
// If you want to use an absolute target path on windows, you can use // `C:\dir\name` format instead.
func (fs *RemoteFileSystem) Symlink(target, linkpath string) error {
if isInvalidPath(target, true) || isInvalidPath(linkpath, false) {
return os.ErrInvalid
Expand Down Expand Up @@ -900,7 +902,7 @@ func (f *RemoteFile) seek(offset int64, whence int) (ret int64, err error) {
req := &QueryInfoRequest{
FileInfoClass: FileStandardInformation,
AdditionalInformation: 0,
Flags: 0,
Flags: 0,
}

infoBytes, err := f.queryInfo(req)
Expand Down Expand Up @@ -933,7 +935,7 @@ func (f *RemoteFile) stat() (os.FileInfo, error) {
req := &QueryInfoRequest{
FileInfoClass: FileAllInformation,
AdditionalInformation: 0,
Flags: 0,
Flags: 0,
}

infoBytes, err := f.queryInfo(req)
Expand All @@ -946,11 +948,6 @@ func (f *RemoteFile) stat() (os.FileInfo, error) {
return nil, &InvalidResponseError{"broken query info response format"}
}

name := UTF16ToString(info.NameInformation().FileName())
if name == "" { // FileNameInformation is empty on windows 10.
name = base(f.name)
}

basic := info.BasicInformation()
std := info.StandardInformation()

Expand All @@ -962,7 +959,7 @@ func (f *RemoteFile) stat() (os.FileInfo, error) {
EndOfFile: std.EndOfFile(),
AllocationSize: std.AllocationSize(),
FileAttributes: basic.FileAttributes(),
FileName: name,
FileName: base(f.name),
}, nil
}

Expand Down
11 changes: 7 additions & 4 deletions client_test.go
Expand Up @@ -50,15 +50,15 @@ type config struct {
func TestClient(t *testing.T) {
var cfg config

cf, err := os.Open(".client_test.conf.json")
cf, err := os.Open("client_conf.json")
if err != nil {
fmt.Println("cannot open .client_test.conf.json")
fmt.Println("cannot open client_conf.json")
t.Skip()
}

err = json.NewDecoder(cf).Decode(&cfg)
if err != nil {
fmt.Println("cannot decode .client_test.conf.json")
fmt.Println("cannot decode client_conf.json")
t.Skip()
}

Expand Down Expand Up @@ -232,7 +232,8 @@ func TestClient(t *testing.T) {
err = fs.Symlink(testDir+`\testFile`, testDir+`\linkToTestFile`)
if !IsPermission(err) {
if err != nil {
t.Fatal(err)
// samba doesn't support reparse point
goto SKIP_SYMLINK_TEST
}
defer fs.Remove(testDir + `\linkToTestFile`)

Expand Down Expand Up @@ -270,6 +271,8 @@ func TestClient(t *testing.T) {
}
}

SKIP_SYMLINK_TEST:

f, err = fs.Create(testDir + `\Exist`)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 0e82d26

Please sign in to comment.