-
Notifications
You must be signed in to change notification settings - Fork 0
/
request-attrs_test.go
58 lines (52 loc) · 1.46 KB
/
request-attrs_test.go
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
package sftp
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRequestPflags(t *testing.T) {
pflags := newFileOpenFlags(sshFxfRead | sshFxfWrite | sshFxfAppend)
assert.True(t, pflags.Read)
assert.True(t, pflags.Write)
assert.True(t, pflags.Append)
assert.False(t, pflags.Creat)
assert.False(t, pflags.Trunc)
assert.False(t, pflags.Excl)
}
func TestRequestAflags(t *testing.T) {
aflags := newFileAttrFlags(
sshFileXferAttrSize | sshFileXferAttrUIDGID)
assert.True(t, aflags.Size)
assert.True(t, aflags.UidGid)
assert.False(t, aflags.Acmodtime)
assert.False(t, aflags.Permissions)
}
func TestRequestAttributes(t *testing.T) {
// UID/GID
fa := FileStat{UID: 1, GID: 2}
fl := uint32(sshFileXferAttrUIDGID)
at := []byte{}
at = marshalUint32(at, 1)
at = marshalUint32(at, 2)
testFs, _ := getFileStat(fl, at)
assert.Equal(t, fa, *testFs)
// Size and Mode
fa = FileStat{Mode: 700, Size: 99}
fl = uint32(sshFileXferAttrSize | sshFileXferAttrPermissions)
at = []byte{}
at = marshalUint64(at, 99)
at = marshalUint32(at, 700)
testFs, _ = getFileStat(fl, at)
assert.Equal(t, fa, *testFs)
// FileMode
assert.True(t, testFs.FileMode().IsRegular())
assert.False(t, testFs.FileMode().IsDir())
assert.Equal(t, testFs.FileMode().Perm(), os.FileMode(700).Perm())
}
func TestRequestAttributesEmpty(t *testing.T) {
fs, b := getFileStat(sshFileXferAttrAll, nil)
assert.Equal(t, &FileStat{
Extended: []StatExtended{},
}, fs)
assert.Empty(t, b)
}