]> git.r.bdr.sh - rbdr/mobius/commitdiff
Appease linter
authorJeff Halter <redacted>
Fri, 19 Jul 2024 23:50:28 +0000 (16:50 -0700)
committerJeff Halter <redacted>
Fri, 19 Jul 2024 23:50:28 +0000 (16:50 -0700)
hotline/field_test.go
hotline/file_resume_data.go
hotline/file_transfer.go
hotline/message_board_test.go [deleted file]
internal/mobius/ban_test.go
internal/mobius/test/config/ThreadedNews.yaml
internal/mobius/threaded_news.go
internal/mobius/threaded_news_test.go
internal/mobius/transaction_handlers.go
internal/mobius/transaction_handlers_test.go

index fc11c74472790de5497195e0eab47fbf0cafcfc5..213d9c3f5bc849298f62b2a4150846e4d91f57e8 100644 (file)
@@ -222,7 +222,7 @@ func TestField_DecodeInt(t *testing.T) {
                                Data: tt.fields.Data,
                        }
                        got, err := f.DecodeInt()
                                Data: tt.fields.Data,
                        }
                        got, err := f.DecodeInt()
-                       if !tt.wantErr(t, err, fmt.Sprintf("DecodeInt()")) {
+                       if !tt.wantErr(t, err) {
                                return
                        }
                        assert.Equalf(t, tt.want, got, "DecodeInt()")
                                return
                        }
                        assert.Equalf(t, tt.want, got, "DecodeInt()")
index b5d980ec58fc988c10a3628b4cb3ec159f6e16cc..5dfd2d81dac2cb8a1b48a14eb02ad91afdc29021 100644 (file)
@@ -13,7 +13,7 @@ type FileResumeData struct {
        ForkCount    [2]byte  // Length of ForkInfoList.  Either 2 or 3 depending on whether file has a resource fork
        ForkInfoList []ForkInfoList
 
        ForkCount    [2]byte  // Length of ForkInfoList.  Either 2 or 3 depending on whether file has a resource fork
        ForkInfoList []ForkInfoList
 
-       readOffset int
+       //readOffset int // TODO
 }
 
 type ForkInfoList struct {
 }
 
 type ForkInfoList struct {
index e37295abd3d581d3140fe090b0a6015841551ab4..806466b927a189c0e811c82ed706b4427d6c6e7a 100644 (file)
@@ -289,14 +289,15 @@ func DownloadHandler(w io.Writer, fullPath string, fileTransfer *FileTransfer, f
                }
        }
 
                }
        }
 
-       rFile, err := fw.rsrcForkFile()
-       if err != nil {
-               // return fmt.Errorf("open resource fork file: %v", err)
-       }
-
-       if _, err = io.Copy(w, io.TeeReader(rFile, fileTransfer.bytesSentCounter)); err != nil {
-               // return fmt.Errorf("send resource fork data: %v", err)
-       }
+       rFile, _ := fw.rsrcForkFile()
+       //if err != nil {
+       //      // return fmt.Errorf("open resource fork file: %v", err)
+       //}
+
+       _, _ = io.Copy(w, io.TeeReader(rFile, fileTransfer.bytesSentCounter))
+       //if err != nil {
+       //      // return fmt.Errorf("send resource fork data: %v", err)
+       //}
 
        return nil
 }
 
        return nil
 }
diff --git a/hotline/message_board_test.go b/hotline/message_board_test.go
deleted file mode 100644 (file)
index 64db714..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-package hotline
-
-import "github.com/stretchr/testify/mock"
-
-type mockReadWriteSeeker struct {
-       mock.Mock
-}
-
-func (m *mockReadWriteSeeker) Read(p []byte) (int, error) {
-       args := m.Called(p)
-
-       return args.Int(0), args.Error(1)
-}
-
-func (m *mockReadWriteSeeker) Write(p []byte) (int, error) {
-       args := m.Called(p)
-
-       return args.Int(0), args.Error(1)
-}
-
-func (m *mockReadWriteSeeker) Seek(offset int64, whence int) (int64, error) {
-       args := m.Called(offset, whence)
-
-       return args.Get(0).(int64), args.Error(1)
-}
index 46860c6ae5aabfbc62d8aea941dcf6f3a73645e7..f03f214755bdf8a4489dab4f493ac9a569613c5d 100644 (file)
@@ -107,7 +107,6 @@ func TestAdd(t *testing.T) {
 func TestBanFile_IsBanned(t *testing.T) {
        type fields struct {
                banList map[string]*time.Time
 func TestBanFile_IsBanned(t *testing.T) {
        type fields struct {
                banList map[string]*time.Time
-               Mutex   sync.Mutex
        }
        type args struct {
                ip string
        }
        type args struct {
                ip string
index 9f3fd65b2b8464957d4593d6d7c37bfaa9396462..ce8beee813535a814cce692a439e5e67101dba7c 100644 (file)
@@ -28,61 +28,7 @@ Categories:
         addsn: []
         deletesn: []
         guid: []
         addsn: []
         deletesn: []
         guid: []
-      TestSubCat:
-        Type:
-        - 0
-        - 3
-        Name: TestSubCat
-        Articles:
-          1:
-            Title: SubCatArt
-            Poster: Halcyon 1.9.2
-            Date:
-            - 7
-            - 228
-            - 0
-            - 0
-            - 0
-            - 254
-            - 252
-            - 246
-            PrevArt:
-            - 0
-            - 0
-            - 0
-            - 0
-            NextArt:
-            - 0
-            - 0
-            - 0
-            - 0
-            ParentArt:
-            - 0
-            - 0
-            - 0
-            - 0
-            FirstChildArtArt:
-            - 0
-            - 0
-            - 0
-            - 0
-            DataFlav:
-            - 116
-            - 101
-            - 120
-            - 116
-            - 47
-            - 112
-            - 108
-            - 97
-            - 105
-            - 110
-            Data: I'm an article in a subcategory!
-        SubCats: {}
-        count: []
-        addsn: []
-        deletesn: []
-        guid: []
+
     count: []
     addsn: []
     deletesn: []
     count: []
     addsn: []
     deletesn: []
index a49055c7ab0ec51b462edf6150d7945c6bb8e1dd..600006abb2a552d99e6d9ff62736ea9308d0e6d7 100644 (file)
@@ -168,13 +168,13 @@ func (n *ThreadedNewsYAML) PostArticle(newsPath []string, parentArticleID uint32
        return n.writeFile()
 }
 
        return n.writeFile()
 }
 
-func (n *ThreadedNewsYAML) DeleteArticle(newsPath []string, articleID uint32, recursive bool) error {
+func (n *ThreadedNewsYAML) DeleteArticle(newsPath []string, articleID uint32, _ bool) error {
        n.mu.Lock()
        defer n.mu.Unlock()
 
        n.mu.Lock()
        defer n.mu.Unlock()
 
-       if recursive {
-               // TODO: Handle delete recursive
-       }
+       //if recursive {
+       //      // TODO: Handle delete recursive
+       //}
 
        cats := n.getCatByPath(newsPath[:len(newsPath)-1])
 
 
        cats := n.getCatByPath(newsPath[:len(newsPath)-1])
 
@@ -214,8 +214,7 @@ func (n *ThreadedNewsYAML) Load() error {
 
        n.ThreadedNews = hotline.ThreadedNews{}
 
 
        n.ThreadedNews = hotline.ThreadedNews{}
 
-       decoder := yaml.NewDecoder(fh)
-       return decoder.Decode(&n.ThreadedNews)
+       return yaml.NewDecoder(fh).Decode(&n.ThreadedNews)
 }
 
 func (n *ThreadedNewsYAML) writeFile() error {
 }
 
 func (n *ThreadedNewsYAML) writeFile() error {
index 9269a858dd45a2632ddc1cb0a0f31df41554b1e0..dd06a28ec5d226d664c0545739747a86b756d356 100644 (file)
@@ -1,8 +1,12 @@
 package mobius
 
 import (
 package mobius
 
 import (
+       "fmt"
+       "github.com/jhalter/mobius/hotline"
        "github.com/stretchr/testify/assert"
        "os"
        "github.com/stretchr/testify/assert"
        "os"
+       "path/filepath"
+       "sync"
        "testing"
 )
 
        "testing"
 )
 
@@ -63,3 +67,148 @@ func TestLoadFromYAMLFile(t *testing.T) {
                })
        }
 }
                })
        }
 }
+
+func TestNewThreadedNewsYAML(t *testing.T) {
+       type args struct {
+               filePath string
+       }
+       tests := []struct {
+               name    string
+               args    args
+               want    *ThreadedNewsYAML
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "Valid YAML file",
+                       args: args{
+                               filePath: "test/config/ThreadedNews.yaml",
+                       },
+                       want: &ThreadedNewsYAML{
+                               filePath: "test/config/ThreadedNews.yaml",
+                               ThreadedNews: hotline.ThreadedNews{
+                                       Categories: map[string]hotline.NewsCategoryListData15{
+                                               "TestBundle": {
+                                                       Type:     hotline.NewsBundle,
+                                                       Name:     "TestBundle",
+                                                       Articles: make(map[uint32]*hotline.NewsArtData),
+                                                       SubCats: map[string]hotline.NewsCategoryListData15{
+                                                               "NestedBundle": {
+                                                                       Name: "NestedBundle",
+                                                                       Type: hotline.NewsBundle,
+                                                                       SubCats: map[string]hotline.NewsCategoryListData15{
+                                                                               "NestedCat": {
+                                                                                       Name:     "NestedCat",
+                                                                                       Type:     hotline.NewsCategory,
+                                                                                       Articles: make(map[uint32]*hotline.NewsArtData),
+                                                                                       SubCats:  make(map[string]hotline.NewsCategoryListData15),
+                                                                               },
+                                                                       },
+                                                                       Articles: make(map[uint32]*hotline.NewsArtData),
+                                                               },
+                                                       },
+                                               },
+                                               "TestCat": {
+                                                       Type: hotline.NewsCategory,
+                                                       Name: "TestCat",
+                                                       Articles: map[uint32]*hotline.NewsArtData{
+                                                               1: {
+                                                                       Title:         "TestArt",
+                                                                       Poster:        "Halcyon 1.9.2",
+                                                                       Date:          [8]byte{0x07, 0xe4, 0x00, 0x00, 0x00, 0xfe, 0xfc, 0xcc},
+                                                                       NextArt:       [4]byte{0, 0, 0, 2},
+                                                                       FirstChildArt: [4]byte{0, 0, 0, 2},
+                                                                       Data:          "TestArt Body",
+                                                               },
+                                                               2: {
+                                                                       Title:     "Re: TestArt",
+                                                                       Poster:    "Halcyon 1.9.2",
+                                                                       Date:      [8]byte{0x07, 0xe4, 0x00, 0x00, 0x00, 0xfe, 0xfc, 0xd8},
+                                                                       PrevArt:   [4]byte{0, 0, 0, 1},
+                                                                       ParentArt: [4]byte{0, 0, 0, 1},
+                                                                       NextArt:   [4]byte{0, 0, 0, 3},
+                                                                       Data:      "I'm a reply",
+                                                               },
+                                                               3: {
+                                                                       Title:   "TestArt 2",
+                                                                       Poster:  "Halcyon 1.9.2",
+                                                                       Date:    [8]byte{0x07, 0xe4, 0x00, 0x00, 0x00, 0xfe, 0xfd, 0x06},
+                                                                       PrevArt: [4]byte{0, 0, 0, 2},
+                                                                       Data:    "Hello world",
+                                                               },
+                                                       },
+                                                       SubCats: make(map[string]hotline.NewsCategoryListData15),
+                                               },
+                                       },
+                               },
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       got, err := NewThreadedNewsYAML(tt.args.filePath)
+                       if !tt.wantErr(t, err, fmt.Sprintf("NewThreadedNewsYAML(%v)", tt.args.filePath)) {
+                               return
+                       }
+                       assert.Equalf(t, tt.want, got, "NewThreadedNewsYAML(%v)", tt.args.filePath)
+               })
+       }
+}
+
+func TestThreadedNewsYAML_CreateGrouping(t *testing.T) {
+       // Create a temporary directory.
+       tmpDir, err := os.MkdirTemp("", "createGrouping")
+       if err != nil {
+               t.Fatalf("Failed to create temp directory: %v", err)
+       }
+       defer os.RemoveAll(tmpDir) // Clean up the temporary directory.
+
+       // Path to the temporary ban file.
+       tmpFilePath := filepath.Join(tmpDir, "ThreadedNews.yaml")
+
+       type fields struct {
+               ThreadedNews hotline.ThreadedNews
+               filePath     string
+       }
+       type args struct {
+               newsPath []string
+               name     string
+               t        [2]byte
+       }
+       tests := []struct {
+               name    string
+               fields  fields
+               args    args
+               wantErr assert.ErrorAssertionFunc
+       }{
+               {
+                       name: "new bundle",
+                       fields: fields{
+                               ThreadedNews: hotline.ThreadedNews{
+                                       Categories: map[string]hotline.NewsCategoryListData15{
+                                               "": {
+                                                       SubCats: make(map[string]hotline.NewsCategoryListData15),
+                                               },
+                                       },
+                               },
+                               filePath: tmpFilePath,
+                       },
+                       args: args{
+                               newsPath: []string{""},
+                               name:     "new bundle",
+                               t:        hotline.NewsBundle,
+                       },
+                       wantErr: assert.NoError,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       n := &ThreadedNewsYAML{
+                               ThreadedNews: tt.fields.ThreadedNews,
+                               filePath:     tt.fields.filePath,
+                               mu:           sync.Mutex{},
+                       }
+                       tt.wantErr(t, n.CreateGrouping(tt.args.newsPath, tt.args.name, tt.args.t), fmt.Sprintf("CreateGrouping(%v, %v, %v)", tt.args.newsPath, tt.args.name, tt.args.t))
+               })
+       }
+}
index 3b07d0e034ce9e8c18dbc4c17e44f17a7d09d513..399a8c038ea4e9ccee9916407f0ba7548cf765a5 100644 (file)
@@ -981,12 +981,11 @@ func HandleDisconnectUser(cc *hotline.ClientConn, t *hotline.Transaction) (res [
 
                        err := cc.Server.BanList.Add(ip, nil)
                        if err != nil {
 
                        err := cc.Server.BanList.Add(ip, nil)
                        if err != nil {
-                               // TODO
+                               cc.Logger.Error("Error saving ban", "err", err)
                        }
                }
        }
 
                        }
                }
        }
 
-       // TODO: remove this awful hack
        go func() {
                time.Sleep(1 * time.Second)
                clientConn.Disconnect()
        go func() {
                time.Sleep(1 * time.Second)
                clientConn.Disconnect()
@@ -1005,14 +1004,15 @@ func HandleGetNewsCatNameList(cc *hotline.ClientConn, t *hotline.Transaction) (r
 
        pathStrs, err := t.GetField(hotline.FieldNewsPath).DecodeNewsPath()
        if err != nil {
 
        pathStrs, err := t.GetField(hotline.FieldNewsPath).DecodeNewsPath()
        if err != nil {
-
+               cc.Logger.Error("get news path", "err", err)
+               return nil
        }
 
        var fields []hotline.Field
        for _, cat := range cc.Server.ThreadedNewsMgr.GetCategories(pathStrs) {
                b, err := io.ReadAll(&cat)
                if err != nil {
        }
 
        var fields []hotline.Field
        for _, cat := range cc.Server.ThreadedNewsMgr.GetCategories(pathStrs) {
                b, err := io.ReadAll(&cat)
                if err != nil {
-                       // TODO
+                       cc.Logger.Error("get news categories", "err", err)
                }
 
                fields = append(fields, hotline.NewField(hotline.FieldNewsCatListData15, b))
                }
 
                fields = append(fields, hotline.NewField(hotline.FieldNewsCatListData15, b))
@@ -1254,7 +1254,7 @@ func HandleGetMsgs(cc *hotline.ClientConn, t *hotline.Transaction) (res []hotlin
 
        newsData, err := io.ReadAll(cc.Server.MessageBoard)
        if err != nil {
 
        newsData, err := io.ReadAll(cc.Server.MessageBoard)
        if err != nil {
-               // TODO
+               cc.Logger.Error("Error reading messageboard", "err", err)
        }
 
        return append(res, cc.NewReply(t, hotline.NewField(hotline.FieldData, newsData)))
        }
 
        return append(res, cc.NewReply(t, hotline.NewField(hotline.FieldData, newsData)))
index 7e9faefc842052e903f65a1b65bd96c196781b7f..63d294662a5edbb4fc0e5d8891378c4592e9e24a 100644 (file)
@@ -3,7 +3,6 @@ package mobius
 import (
        "cmp"
        "encoding/binary"
 import (
        "cmp"
        "encoding/binary"
-       "encoding/hex"
        "errors"
        "github.com/jhalter/mobius/hotline"
        "github.com/stretchr/testify/assert"
        "errors"
        "github.com/jhalter/mobius/hotline"
        "github.com/stretchr/testify/assert"
@@ -45,24 +44,6 @@ func NewTestLogger() *slog.Logger {
        return slog.New(slog.NewTextHandler(os.Stdout, nil))
 }
 
        return slog.New(slog.NewTextHandler(os.Stdout, nil))
 }
 
-// assertTransferBytesEqual takes a string with a hexdump in the same format that `hexdump -C` produces and compares with
-// a hexdump for the bytes in got, after stripping the create/modify timestamps.
-// I don't love this, but as git does not  preserve file create/modify timestamps, we either need to fully mock the
-// filesystem interactions or work around in this way.
-// TODO: figure out a better solution
-func assertTransferBytesEqual(t *testing.T, wantHexDump string, got []byte) bool {
-       if wantHexDump == "" {
-               return true
-       }
-
-       clean := slices.Concat(
-               got[:92],
-               make([]byte, 16),
-               got[108:],
-       )
-       return assert.Equal(t, wantHexDump, hex.Dump(clean))
-}
-
 var tranSortFunc = func(a, b hotline.Transaction) int {
        return cmp.Compare(
                binary.BigEndian.Uint16(a.ClientID[:]),
 var tranSortFunc = func(a, b hotline.Transaction) int {
        return cmp.Compare(
                binary.BigEndian.Uint16(a.ClientID[:]),