Skip to content

Commit

Permalink
Make tests compile with GOOS=windows
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Jun 19, 2023
1 parent be1cd54 commit 2fc52b1
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 70 deletions.
6 changes: 6 additions & 0 deletions internal/goofys.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ func ParseBucketSpec(bucket string) (spec BucketSpec, err error) {
}

func NewGoofys(ctx context.Context, bucketName string, flags *cfg.FlagStorage) (*Goofys, error) {
if flags.DebugFuse || flags.DebugMain {
log.Level = logrus.DebugLevel
}
if flags.DebugFuse {
fuseLog.Level = logrus.DebugLevel
}
if flags.DebugS3 {
cfg.SetCloudLogLevel(logrus.DebugLevel)
}
Expand Down
50 changes: 3 additions & 47 deletions internal/goofys_fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,11 @@ import (
)

func (s *GoofysTest) mount(t *C, mountPoint string) {
s.mountSame(t, mountPoint, false)
s.mountCommon(t, mountPoint, false)
}

func (s *GoofysTest) mountSame(t *C, mountPoint string, sameProc bool) {
err := os.MkdirAll(mountPoint, 0700)
if err == syscall.EEXIST {
err = nil
}
t.Assert(err, IsNil)

if !hasEnv("SAME_PROCESS_MOUNT") && !sameProc {

region := ""
if os.Getenv("REGION") != "" {
region = " --region \""+os.Getenv("REGION")+"\""
}
exe := os.Getenv("GEESEFS_BINARY")
if exe == "" {
exe = "../geesefs"
}
c := exec.Command("/bin/bash", "-c",
exe+" --debug_fuse --debug_s3"+
" --stat-cache-ttl "+s.fs.flags.StatCacheTTL.String()+
" --log-file \"mount_"+t.TestName()+".log\""+
" --endpoint \""+s.fs.flags.Endpoint+"\""+
region+
" "+s.fs.bucket+" "+mountPoint)
err = c.Run()
t.Assert(err, IsNil)

} else {
s.mfs, err = mountFuseFS(s.fs)
t.Assert(err, IsNil)
}
}

func (s *GoofysTest) umount(t *C, mountPoint string) {
var err error
for i := 0; i < 10; i++ {
err = TryUnmount(mountPoint)
if err != nil {
time.Sleep(100 * time.Millisecond)
} else {
break
}
}
t.Assert(err, IsNil)

os.Remove(mountPoint)
func (s *GoofysTest) mountInside(t *C, mountPoint string) {
s.mountCommon(t, mountPoint, true)
}

func (s *GoofysTest) TestIssue69Fuse(t *C) {
Expand Down
5 changes: 0 additions & 5 deletions internal/goofys_fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,14 +901,9 @@ func mountFuseFS(fs *Goofys) (mfs MountedFS, err error) {

if fs.flags.DebugFuse {
fuseLog := cfg.GetLogger("fuse")
fuseLog.Level = logrus.DebugLevel
mountCfg.DebugLogger = cfg.GetStdLogger(fuseLog, logrus.DebugLevel)
}

if fs.flags.DebugFuse || fs.flags.DebugMain {
log.Level = logrus.DebugLevel
}

fsint := NewGoofysFuse(fs)
server := fuseutil.NewFileSystemServer(fsint)

Expand Down
53 changes: 51 additions & 2 deletions internal/goofys_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"os/exec"
"runtime"
"sync"
"syscall"
"time"

"golang.org/x/sys/unix"
Expand All @@ -42,6 +43,54 @@ import (
test_embed "github.com/yandex-cloud/geesefs/test"
)

func (s *GoofysTest) mountCommon(t *C, mountPoint string, sameProc bool) {
err := os.MkdirAll(mountPoint, 0700)
if err == syscall.EEXIST {
err = nil
}
t.Assert(err, IsNil)

if !hasEnv("SAME_PROCESS_MOUNT") && !sameProc {

region := ""
if os.Getenv("REGION") != "" {
region = " --region \""+os.Getenv("REGION")+"\""
}
exe := os.Getenv("GEESEFS_BINARY")
if exe == "" {
exe = "../geesefs"
}
c := exec.Command("/bin/bash", "-c",
exe+" --debug_fuse --debug_s3"+
" --stat-cache-ttl "+s.fs.flags.StatCacheTTL.String()+
" --log-file \"mount_"+t.TestName()+".log\""+
" --endpoint \""+s.fs.flags.Endpoint+"\""+
region+
" "+s.fs.bucket+" "+mountPoint)
err = c.Run()
t.Assert(err, IsNil)

} else {
s.mfs, err = mountFuseFS(s.fs)
t.Assert(err, IsNil)
}
}

func (s *GoofysTest) umount(t *C, mountPoint string) {
var err error
for i := 0; i < 10; i++ {
err = TryUnmount(mountPoint)
if err != nil {
time.Sleep(100 * time.Millisecond)
} else {
break
}
}
t.Assert(err, IsNil)

os.Remove(mountPoint)
}

func (s *GoofysTest) SetUpSuite(t *C) {
s.tmp = os.Getenv("TMPDIR")
if s.tmp == "" {
Expand Down Expand Up @@ -446,7 +495,7 @@ func (s *GoofysTest) TestNestedMountUnmountSimple(t *C) {
s.setupBlobs(childCloud, t, childEnv)

rootMountPath := s.tmp + "/fusetesting/" + RandStringBytesMaskImprSrc(16)
s.mountSame(t, rootMountPath, true)
s.mountInside(t, rootMountPath)
defer s.umount(t, rootMountPath)
// Files under /tmp/fusetesting/ should all be from goofys root.
verifyFileData(t, rootMountPath, "childmnt/x/in_par_only", &parFileContent)
Expand Down Expand Up @@ -500,7 +549,7 @@ func (s *GoofysTest) TestUnmountBucketWithChild(t *C) {
s.setupBlobs(ccCloud, t, ccEnv)

rootMountPath := s.tmp + "/fusetesting/" + RandStringBytesMaskImprSrc(16)
s.mountSame(t, rootMountPath, true)
s.mountInside(t, rootMountPath)
defer s.umount(t, rootMountPath)
// c/c/foo should come from root mount.
verifyFileData(t, rootMountPath, "c/c/x/foo", &pFileContent)
Expand Down
27 changes: 11 additions & 16 deletions internal/goofys_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,30 +908,25 @@ func MountWin(
ctx context.Context,
bucketName string,
flags *cfg.FlagStorage) (fs *Goofys, mfs MountedFS, err error) {

if flags.DebugFuse || flags.DebugMain {
log.Level = logrus.DebugLevel
}

if flags.DebugFuse {
fuseLog.Level = logrus.DebugLevel
}

fs, err = NewGoofys(ctx, bucketName, flags)
if fs == nil {
if err == nil {
err = fmt.Errorf("GeeseFS initialization failed")
}
return
}
mfs, err = mountFuseFS(fs)
return
}

func mountFuseFS(fs *Goofys) (mfs MountedFS, err error) {
var mountOpt []string
if flags.DebugFuse {
if fs.flags.DebugFuse {
mountOpt = append(mountOpt, "-o", "debug")
}
mountOpt = append(mountOpt, "-o", fmt.Sprintf("uid=%v", int32(flags.Uid)))
mountOpt = append(mountOpt, "-o", fmt.Sprintf("gid=%v", int32(flags.Gid)))
for _, s := range flags.MountOptions {
mountOpt = append(mountOpt, "-o", fmt.Sprintf("uid=%v", int32(fs.flags.Uid)))
mountOpt = append(mountOpt, "-o", fmt.Sprintf("gid=%v", int32(fs.flags.Gid)))
for _, s := range fs.flags.MountOptions {
mountOpt = append(mountOpt, "-o", s)
}
fuseLog.Debugf("Starting WinFSP with options: %v", mountOpt)
Expand All @@ -942,17 +937,17 @@ func MountWin(
fsint.host = host
host.SetCapReaddirPlus(true)
go func() {
ok := host.Mount(flags.MountPoint, mountOpt)
ok := host.Mount(fs.flags.MountPoint, mountOpt)
if !ok {
fsint.initCh <- 0
}
}()
v := <-fsint.initCh
if v == 0 {
return nil, nil, fmt.Errorf("WinFSP initialization failed")
return nil, fmt.Errorf("WinFSP initialization failed")
}

return fs, fsint, nil
return fsint, nil
}

// Join is a part of MountedFS interface
Expand Down
44 changes: 44 additions & 0 deletions internal/goofys_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2015 - 2017 Ka-Hing Cheung
// Copyright 2021 Yandex LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Tests for a mounted Windows WinFSP-FUSE FS

// +build windows

package internal

import (
"os"
. "gopkg.in/check.v1"
)

func (s *GoofysTest) SetUpSuite(t *C) {
s.tmp = os.Getenv("TMPDIR")
if s.tmp == "" {
s.tmp = os.TempDir()
}
}

func (s *GoofysTest) mountCommon(t *C, mountPoint string, sameProc bool) {
os.Remove(mountPoint)
mfs, err := mountFuseFS(s.fs)
t.Assert(err, IsNil)
s.mfs = mfs
}

func (s *GoofysTest) umount(t *C, mountPoint string) {
s.mfs.Unmount()
s.mfs = nil
}

0 comments on commit 2fc52b1

Please sign in to comment.