From d66a0674cac8fb987e6ec8762726fcf8a28b6b6e Mon Sep 17 00:00:00 2001 From: Michail Kargakis Date: Fri, 10 Apr 2020 23:58:56 +0200 Subject: [PATCH 1/2] Add gofmt and go vet checks in CI --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 067282d..0f0b9d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,4 +18,5 @@ matrix: script: - go build -v ./... - go test -count=1 -cover -race -v ./... - + - go vet ./... + - FILES=$(gofmt -s -l . zipfs sftpfs mem); if [[ -n "${FILES}" ]]; then echo "You have go format errors; gofmt your changes"; exit 1; fi From 90f4ffe95f275cf7244cf3c6dcfe6b7c79c51f1a Mon Sep 17 00:00:00 2001 From: Michail Kargakis Date: Fri, 10 Apr 2020 23:50:34 +0200 Subject: [PATCH 2/2] Gofmt the project --- basepath_test.go | 14 +++++----- match_test.go | 1 - memmap.go | 2 +- sftpfs/sftp_test.go | 66 ++++++++++++++++++++++----------------------- util_test.go | 20 +++++++------- zipfs/file.go | 2 +- 6 files changed, 52 insertions(+), 53 deletions(-) diff --git a/basepath_test.go b/basepath_test.go index 77aa7df..e314c05 100644 --- a/basepath_test.go +++ b/basepath_test.go @@ -96,10 +96,10 @@ func TestNestedBasePaths(t *testing.T) { Dir1, Dir2, Dir3 string } dirSpecs := []dirSpec{ - dirSpec{Dir1: "/", Dir2: "/", Dir3: "/"}, - dirSpec{Dir1: "/", Dir2: "/path2", Dir3: "/"}, - dirSpec{Dir1: "/path1/dir", Dir2: "/path2/dir/", Dir3: "/path3/dir"}, - dirSpec{Dir1: "C:/path1", Dir2: "path2/dir", Dir3: "/path3/dir/"}, + {Dir1: "/", Dir2: "/", Dir3: "/"}, + {Dir1: "/", Dir2: "/path2", Dir3: "/"}, + {Dir1: "/path1/dir", Dir2: "/path2/dir/", Dir3: "/path3/dir"}, + {Dir1: "C:/path1", Dir2: "path2/dir", Dir3: "/path3/dir/"}, } for _, ds := range dirSpecs { @@ -113,9 +113,9 @@ func TestNestedBasePaths(t *testing.T) { FileName string } specs := []spec{ - spec{BaseFs: level3Fs, FileName: "f.txt"}, - spec{BaseFs: level2Fs, FileName: "f.txt"}, - spec{BaseFs: level1Fs, FileName: "f.txt"}, + {BaseFs: level3Fs, FileName: "f.txt"}, + {BaseFs: level2Fs, FileName: "f.txt"}, + {BaseFs: level1Fs, FileName: "f.txt"}, } for _, s := range specs { diff --git a/match_test.go b/match_test.go index 21e1fae..fa2c17b 100644 --- a/match_test.go +++ b/match_test.go @@ -172,7 +172,6 @@ func TestGlobSymlink(t *testing.T) { } } - func TestGlobError(t *testing.T) { for _, fs := range Fss { _, err := Glob(fs, "[7]") diff --git a/memmap.go b/memmap.go index 09498e7..943bad0 100644 --- a/memmap.go +++ b/memmap.go @@ -269,7 +269,7 @@ func (m *MemMapFs) RemoveAll(path string) error { m.mu.RLock() defer m.mu.RUnlock() - for p, _ := range m.getData() { + for p := range m.getData() { if strings.HasPrefix(p, path) { m.mu.RUnlock() m.mu.Lock() diff --git a/sftpfs/sftp_test.go b/sftpfs/sftp_test.go index 9df21c9..4dba7fc 100644 --- a/sftpfs/sftp_test.go +++ b/sftpfs/sftp_test.go @@ -14,21 +14,21 @@ package sftpfs import ( - "testing" - "os" - "log" - "fmt" - "net" - "flag" - "time" - "io/ioutil" - "crypto/rsa" _rand "crypto/rand" - "encoding/pem" + "crypto/rsa" "crypto/x509" + "encoding/pem" + "flag" + "fmt" + "io/ioutil" + "log" + "net" + "os" + "testing" + "time" - "golang.org/x/crypto/ssh" "github.com/pkg/sftp" + "golang.org/x/crypto/ssh" ) type SftpFsContext struct { @@ -40,25 +40,25 @@ type SftpFsContext struct { // TODO we only connect with hardcoded user+pass for now // it should be possible to use $HOME/.ssh/id_rsa to login into the stub sftp server func SftpConnect(user, password, host string) (*SftpFsContext, error) { -/* - pemBytes, err := ioutil.ReadFile(os.Getenv("HOME") + "/.ssh/id_rsa") - if err != nil { - return nil,err - } + /* + pemBytes, err := ioutil.ReadFile(os.Getenv("HOME") + "/.ssh/id_rsa") + if err != nil { + return nil,err + } - signer, err := ssh.ParsePrivateKey(pemBytes) - if err != nil { - return nil,err - } + signer, err := ssh.ParsePrivateKey(pemBytes) + if err != nil { + return nil,err + } - sshcfg := &ssh.ClientConfig{ - User: user, - Auth: []ssh.AuthMethod{ - ssh.Password(password), - ssh.PublicKeys(signer), - }, - } -*/ + sshcfg := &ssh.ClientConfig{ + User: user, + Auth: []ssh.AuthMethod{ + ssh.Password(password), + ssh.PublicKeys(signer), + }, + } + */ sshcfg := &ssh.ClientConfig{ User: user, @@ -70,21 +70,21 @@ func SftpConnect(user, password, host string) (*SftpFsContext, error) { sshc, err := ssh.Dial("tcp", host, sshcfg) if err != nil { - return nil,err + return nil, err } sftpc, err := sftp.NewClient(sshc) if err != nil { - return nil,err + return nil, err } ctx := &SftpFsContext{ - sshc: sshc, + sshc: sshc, sshcfg: sshcfg, - sftpc: sftpc, + sftpc: sftpc, } - return ctx,nil + return ctx, nil } func (ctx *SftpFsContext) Disconnect() error { diff --git a/util_test.go b/util_test.go index b5852f1..d2145cf 100644 --- a/util_test.go +++ b/util_test.go @@ -415,10 +415,10 @@ func TestFullBaseFsPath(t *testing.T) { Dir1, Dir2, Dir3 string } dirSpecs := []dirSpec{ - dirSpec{Dir1: "/", Dir2: "/", Dir3: "/"}, - dirSpec{Dir1: "/", Dir2: "/path2", Dir3: "/"}, - dirSpec{Dir1: "/path1/dir", Dir2: "/path2/dir/", Dir3: "/path3/dir"}, - dirSpec{Dir1: "C:/path1", Dir2: "path2/dir", Dir3: "/path3/dir/"}, + {Dir1: "/", Dir2: "/", Dir3: "/"}, + {Dir1: "/", Dir2: "/path2", Dir3: "/"}, + {Dir1: "/path1/dir", Dir2: "/path2/dir/", Dir3: "/path3/dir"}, + {Dir1: "C:/path1", Dir2: "path2/dir", Dir3: "/path3/dir/"}, } for _, ds := range dirSpecs { @@ -433,12 +433,12 @@ func TestFullBaseFsPath(t *testing.T) { ExpectedPath string } specs := []spec{ - spec{BaseFs: level3Fs, FileName: "f.txt", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, ds.Dir3, "f.txt")}, - spec{BaseFs: level3Fs, FileName: "", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, ds.Dir3, "")}, - spec{BaseFs: level2Fs, FileName: "f.txt", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, "f.txt")}, - spec{BaseFs: level2Fs, FileName: "", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, "")}, - spec{BaseFs: level1Fs, FileName: "f.txt", ExpectedPath: filepath.Join(ds.Dir1, "f.txt")}, - spec{BaseFs: level1Fs, FileName: "", ExpectedPath: filepath.Join(ds.Dir1, "")}, + {BaseFs: level3Fs, FileName: "f.txt", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, ds.Dir3, "f.txt")}, + {BaseFs: level3Fs, FileName: "", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, ds.Dir3, "")}, + {BaseFs: level2Fs, FileName: "f.txt", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, "f.txt")}, + {BaseFs: level2Fs, FileName: "", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, "")}, + {BaseFs: level1Fs, FileName: "f.txt", ExpectedPath: filepath.Join(ds.Dir1, "f.txt")}, + {BaseFs: level1Fs, FileName: "", ExpectedPath: filepath.Join(ds.Dir1, "")}, } for _, s := range specs { diff --git a/zipfs/file.go b/zipfs/file.go index 94f9ddc..6475cdd 100644 --- a/zipfs/file.go +++ b/zipfs/file.go @@ -142,7 +142,7 @@ func (f *File) Readdirnames(count int) (names []string, err error) { if err != nil { return nil, err } - for filename, _ := range zipfiles { + for filename := range zipfiles { names = append(names, filename) if count >= 0 && len(names) >= count { break