golint and go vet fixes
diff --git a/request-server_test.go b/request-server_test.go
index 4902349..5270fad 100644
--- a/request-server_test.go
+++ b/request-server_test.go
@@ -29,7 +29,7 @@
return cs.svr.Handlers.FileGet.(*root)
}
-var sock string = "/tmp/rstest.sock"
+const sock = "/tmp/rstest.sock"
func clientRequestServerPair(t *testing.T) *csPair {
ready := make(chan bool)
diff --git a/request.go b/request.go
index 8ef34fd..fb54508 100644
--- a/request.go
+++ b/request.go
@@ -20,11 +20,10 @@
Attrs []byte // convert to sub-struct
Target string // for renames and sym-links
// packet data
- pkt_id uint32
- packetsLock sync.Mutex
- packets chan packet_data
+ pkt_id uint32
+ packets chan packet_data
// reader/writer/readdir from handlers
- stateLock sync.RWMutex
+ stateLock *sync.RWMutex
state *state
}
@@ -53,6 +52,7 @@
request := Request{Filepath: filepath.Clean(path)}
request.packets = make(chan packet_data, sftpServerWorkerCount)
request.state = &state{}
+ request.stateLock = &sync.RWMutex{}
return request
}
diff --git a/request_test.go b/request_test.go
index b89b5a4..e537fc1 100644
--- a/request_test.go
+++ b/request_test.go
@@ -1,6 +1,8 @@
package sftp
import (
+ "sync"
+
"github.com/stretchr/testify/assert"
"bytes"
@@ -55,16 +57,17 @@
// make sure len(fakefile) == len(filecontents)
type fakefile [10]byte
-var filecontents []byte = []byte("file-data.")
+var filecontents = []byte("file-data.")
func testRequest(method string) Request {
request := Request{
- Filepath: "./request_test.go",
- Method: method,
- Attrs: []byte("foo"),
- Target: "foo",
- packets: make(chan packet_data, sftpServerWorkerCount),
- state: &state{},
+ Filepath: "./request_test.go",
+ Method: method,
+ Attrs: []byte("foo"),
+ Target: "foo",
+ packets: make(chan packet_data, sftpServerWorkerCount),
+ state: &state{},
+ stateLock: &sync.RWMutex{},
}
for _, p := range []packet_data{
packet_data{id: 1, data: filecontents[:5], length: 5},
@@ -162,7 +165,8 @@
request := testRequest("Stat")
pkt, err := request.handle(handlers)
assert.Nil(t, err)
- spkt := pkt.(*sshFxpStatResponse)
+ spkt, ok := pkt.(*sshFxpStatResponse)
+ assert.True(t, ok)
assert.Equal(t, spkt.info.Name(), "request_test.go")
}