Skip to content

Commit

Permalink
Refactored attribute test to deal with new types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Donavan Pantke committed Jun 23, 2014
1 parent 5ea2cc5 commit 9e90e6c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions attrs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,40 @@ import (
"os"
"reflect"
"testing"
"time"
)

// ensure that attrs implemenst os.FileInfo
var _ os.FileInfo = new(attr)
var _ os.FileInfo = new(fileInfo)

var unmarshalAttrsTests = []struct {
b []byte
want attr
want *fileInfo
rest []byte
}{
{marshal(nil, struct{ Flags uint32 }{}), attr{}, nil},
{marshal(nil, struct{ Flags uint32 }{}), &fileInfo{mtime: time.Unix(int64(0), 0)}, nil},
{marshal(nil, struct {
Flags uint32
Size uint64
}{ssh_FILEXFER_ATTR_SIZE, 20}), attr{size: 20}, nil},
}{ssh_FILEXFER_ATTR_SIZE, 20}), &fileInfo{size: 20, mtime: time.Unix(int64(0), 0)}, nil},
{marshal(nil, struct {
Flags uint32
Size uint64
Permissions uint32
}{ssh_FILEXFER_ATTR_SIZE | ssh_FILEXFER_ATTR_PERMISSIONS, 20, 0644}), attr{size: 20, mode: os.FileMode(0644)}, nil},
}{ssh_FILEXFER_ATTR_SIZE | ssh_FILEXFER_ATTR_PERMISSIONS, 20, 0644}), &fileInfo{size: 20, mode: os.FileMode(0644), mtime: time.Unix(int64(0), 0)}, nil},
{marshal(nil, struct {
Flags uint32
Size uint64
Uid, Gid, Permissions uint32
}{ssh_FILEXFER_ATTR_SIZE | ssh_FILEXFER_ATTR_UIDGID | ssh_FILEXFER_ATTR_UIDGID | ssh_FILEXFER_ATTR_PERMISSIONS, 20, 1000, 1000, 0644}), attr{size: 20, mode: os.FileMode(0644)}, nil},
}{ssh_FILEXFER_ATTR_SIZE | ssh_FILEXFER_ATTR_UIDGID | ssh_FILEXFER_ATTR_UIDGID | ssh_FILEXFER_ATTR_PERMISSIONS, 20, 1000, 1000, 0644}), &fileInfo{size: 20, mode: os.FileMode(0644), mtime: time.Unix(int64(0), 0)}, nil},
}

func TestUnmarshalAttrs(t *testing.T) {
for _, tt := range unmarshalAttrsTests {
got, rest := unmarshalAttrs(tt.b)
if !reflect.DeepEqual(*got, tt.want) || !bytes.Equal(tt.rest, rest) {
stat, rest := unmarshalAttrs(tt.b)
got := fileInfoFromStat(stat, "")
tt.want.sys = got.Sys()
if !reflect.DeepEqual(got, tt.want) || !bytes.Equal(tt.rest, rest) {
t.Errorf("unmarshalAttrs(%#v): want %#v, %#v, got: %#v, %#v", tt.b, tt.want, tt.rest, got, rest)
}
}
Expand Down

0 comments on commit 9e90e6c

Please sign in to comment.