+
+func TestHandleGetFileInfo(t *testing.T) {
+ rand.Seed(1) // reset seed between tests to make transaction IDs predictable
+
+ type args struct {
+ cc *ClientConn
+ t *Transaction
+ }
+ tests := []struct {
+ name string
+ args args
+ wantRes []Transaction
+ wantErr bool
+ }{
+ {
+ name: "returns expected fields when a valid file is requested",
+ args: args{
+ cc: &ClientConn{
+ ID: &[]byte{0x00, 0x01},
+ Server: &Server{
+ Config: &Config{
+ FileRoot: "./test/config/Files/",
+ },
+ },
+ },
+ t: NewTransaction(
+ tranGetFileInfo, nil,
+ NewField(fieldFileName, []byte("testfile.txt")),
+ NewField(fieldFilePath, []byte{0x00, 0x00}),
+ //NewField(fieldFilePath, []byte{
+ // 0x00, 0x03,
+ // 0x00, 0x00,
+ // 0x04,
+ // 0x74, 0x65, 0x73, 0x74,
+ // 0x00, 0x00,
+ // 0x06,
+ // 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67,
+ //
+ // 0x00, 0x00,
+ // 0x05,
+ // 0x46, 0x69, 0x6c, 0x65, 73},
+ //),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ clientID: &[]byte{0, 1},
+ Flags: 0x00,
+ IsReply: 0x01,
+ Type: []byte{0, 0xce},
+ ID: []byte{0x9a, 0xcb, 0x04, 0x42}, // Random ID from rand.Seed(1)
+ ErrorCode: []byte{0, 0, 0, 0},
+ Fields: []Field{
+ NewField(fieldFileName, []byte("testfile.txt")),
+ NewField(fieldFileTypeString, []byte("TEXT")),
+ NewField(fieldFileCreatorString, []byte("TTXT")),
+ NewField(fieldFileComment, []byte("TODO")),
+ NewField(fieldFileType, []byte("TEXT")),
+ NewField(fieldFileCreateDate, []byte{0x07, 0x70, 0x00, 0x00, 0xba, 0x74, 0x24, 0x73}),
+ NewField(fieldFileModifyDate, []byte{0x07, 0x70, 0x00, 0x00, 0xba, 0x74, 0x24, 0x73}),
+ NewField(fieldFileSize, []byte{0x0, 0x0, 0x0, 0x17}),
+ },
+ },
+ },
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ rand.Seed(1) // reset seed between tests to make transaction IDs predictable
+
+ gotRes, err := HandleGetFileInfo(tt.args.cc, tt.args.t)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("HandleGetFileInfo() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !assert.Equal(t, tt.wantRes, gotRes) {
+ t.Errorf("HandleGetFileInfo() gotRes = %v, want %v", gotRes, tt.wantRes)
+ }
+ })
+ }
+}