X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/76d0c1f61d5981603389e6267bf62636f34bef1f..5cc444c89968dda9060d4e2f458b1babb9b603cd:/hotline/transaction_handlers_test.go?ds=sidebyside diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go index 89ee9fc..81ba6e0 100644 --- a/hotline/transaction_handlers_test.go +++ b/hotline/transaction_handlers_test.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "io" "io/fs" "math/rand" "os" @@ -768,7 +769,6 @@ func TestHandleGetFileInfo(t *testing.T) { NewField(FieldFileName, []byte("testfile.txt")), NewField(FieldFileTypeString, []byte("Text File")), NewField(FieldFileCreatorString, []byte("ttxt")), - NewField(FieldFileComment, []byte{}), NewField(FieldFileType, []byte("TEXT")), NewField(FieldFileCreateDate, make([]byte, 8)), NewField(FieldFileModifyDate, make([]byte, 8)), @@ -791,8 +791,8 @@ func TestHandleGetFileInfo(t *testing.T) { // Clear the fileWrapper timestamp fields to work around problems running the tests in multiple timezones // TODO: revisit how to test this by mocking the stat calls + gotRes[0].Fields[4].Data = make([]byte, 8) gotRes[0].Fields[5].Data = make([]byte, 8) - gotRes[0].Fields[6].Data = make([]byte, 8) if !assert.Equal(t, tt.wantRes, gotRes) { t.Errorf("HandleGetFileInfo() gotRes = %v, want %v", gotRes, tt.wantRes) } @@ -2860,7 +2860,7 @@ func TestHandleGetFileNameList(t *testing.T) { }, name: []byte("testfile-1k"), } - b, _ := fnwi.MarshalBinary() + b, _ := io.ReadAll(&fnwi) return b }(), ), @@ -3191,7 +3191,7 @@ func TestHandleDelNewsItem(t *testing.T) { Server: &Server{ ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{ "test": { - Type: []byte{0, 3}, + Type: [2]byte{0, 3}, Count: nil, NameSize: 0, Name: "zz", @@ -3237,7 +3237,7 @@ func TestHandleDelNewsItem(t *testing.T) { Server: &Server{ ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{ "testcat": { - Type: []byte{0, 2}, + Type: [2]byte{0, 2}, Count: nil, NameSize: 0, Name: "test", @@ -3293,7 +3293,7 @@ func TestHandleDelNewsItem(t *testing.T) { }(), ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{ "testcat": { - Type: []byte{0, 2}, + Type: [2]byte{0, 2}, Count: nil, NameSize: 0, Name: "test", @@ -3338,72 +3338,6 @@ func TestHandleDelNewsItem(t *testing.T) { } } -func TestHandleDownloadBanner(t *testing.T) { - type args struct { - cc *ClientConn - t *Transaction - } - tests := []struct { - name string - args args - wantRes []Transaction - wantErr assert.ErrorAssertionFunc - }{ - { - name: "returns expected response", - args: args{ - cc: &ClientConn{ - ID: &[]byte{0, 1}, - transfers: map[int]map[[4]byte]*FileTransfer{ - bannerDownload: {}, - }, - Server: &Server{ - ConfigDir: "/config", - Config: &Config{ - BannerFile: "banner.jpg", - }, - fileTransfers: map[[4]byte]*FileTransfer{}, - FS: func() *MockFileStore { - mfi := &MockFileInfo{} - mfi.On("Size").Return(int64(100)) - - mfs := &MockFileStore{} - mfs.On("Stat", "/config/banner.jpg").Return(mfi, nil) - return mfs - }(), - }, - }, - t: NewTransaction(TranDownloadBanner, nil), - }, - wantRes: []Transaction{ - { - clientID: &[]byte{0, 1}, - Flags: 0x00, - IsReply: 0x01, - Type: []byte{0, 0}, - ID: []byte{0, 0, 0, 0}, - ErrorCode: []byte{0, 0, 0, 0}, - Fields: []Field{ - NewField(FieldRefNum, []byte{1, 2, 3, 4}), - NewField(FieldTransferSize, []byte{0, 0, 0, 0x64}), - }, - }, - }, - wantErr: assert.NoError, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - gotRes, err := HandleDownloadBanner(tt.args.cc, tt.args.t) - if !tt.wantErr(t, err, fmt.Sprintf("HandleDownloadBanner(%v, %v)", tt.args.cc, tt.args.t)) { - return - } - - tranAssertEqual(t, tt.wantRes, gotRes) - }) - } -} - func TestHandleTranOldPostNews(t *testing.T) { type args struct { cc *ClientConn @@ -3847,7 +3781,7 @@ func TestHandleNewNewsFldr(t *testing.T) { }(), ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{ "test": { - Type: []byte{0, 2}, + Type: [2]byte{0, 2}, Count: nil, NameSize: 0, Name: "test",