4 "github.com/stretchr/testify/assert"
5 "github.com/stretchr/testify/mock"
10 type mockThreadNewsMgr struct {
14 func (m *mockThreadNewsMgr) ListArticles(newsPath []string) NewsArtListData {
15 args := m.Called(newsPath)
17 return args.Get(0).(NewsArtListData)
20 func (m *mockThreadNewsMgr) GetArticle(newsPath []string, articleID uint32) *NewsArtData {
21 args := m.Called(newsPath, articleID)
23 return args.Get(0).(*NewsArtData)
25 func (m *mockThreadNewsMgr) DeleteArticle(newsPath []string, articleID uint32, recursive bool) error {
26 args := m.Called(newsPath, articleID, recursive)
31 func (m *mockThreadNewsMgr) PostArticle(newsPath []string, parentArticleID uint32, article NewsArtData) error {
32 args := m.Called(newsPath, parentArticleID, article)
36 func (m *mockThreadNewsMgr) CreateGrouping(newsPath []string, name string, itemType [2]byte) error {
37 args := m.Called(newsPath, name, itemType)
42 func (m *mockThreadNewsMgr) GetCategories(paths []string) []NewsCategoryListData15 {
43 args := m.Called(paths)
45 return args.Get(0).([]NewsCategoryListData15)
48 func (m *mockThreadNewsMgr) NewsItem(newsPath []string) NewsCategoryListData15 {
49 args := m.Called(newsPath)
51 return args.Get(0).(NewsCategoryListData15)
54 func (m *mockThreadNewsMgr) DeleteNewsItem(newsPath []string) error {
55 args := m.Called(newsPath)
60 func TestNewsCategoryListData15_MarshalBinary(t *testing.T) {
64 Articles map[uint32]*NewsArtData
65 SubCats map[string]NewsCategoryListData15
78 name: "returns expected bytes when type is a bundle",
80 Type: [2]byte{0x00, 0x02},
81 Articles: map[uint32]*NewsArtData{
99 name: "returns expected bytes when type is a category",
101 Type: [2]byte{0x00, 0x03},
102 Articles: map[uint32]*NewsArtData{
114 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
115 0x00, 0x00, 0x00, 0x00,
116 0x00, 0x00, 0x00, 0x00,
123 for _, tt := range tests {
124 t.Run(tt.name, func(t *testing.T) {
125 newscat := &NewsCategoryListData15{
126 Type: tt.fields.Type,
127 Name: tt.fields.Name,
128 Articles: tt.fields.Articles,
129 SubCats: tt.fields.SubCats,
130 AddSN: tt.fields.AddSN,
131 DeleteSN: tt.fields.DeleteSN,
132 GUID: tt.fields.GUID,
134 gotData, err := io.ReadAll(newscat)
135 if newscat.Type == [2]byte{0, 3} {
136 // zero out the random GUID before comparison
137 for i := 4; i < 20; i++ {
141 if (err != nil) != tt.wantErr {
142 t.Errorf("MarshalBinary() error = %v, wantErr %v", err, tt.wantErr)
145 if !assert.Equal(t, tt.wantData, gotData) {
146 t.Errorf("MarshalBinary() gotData = %v, want %v", gotData, tt.wantData)