Add unit tests for Reticulum-Go packages including reticulum, storage, announce, channel, destination, identity, resource, and transport, ensuring comprehensive coverage of functionality.
Some checks failed
Go Build Multi-Platform / build (amd64, freebsd) (push) Successful in 51s
Go Build Multi-Platform / build (amd64, windows) (push) Successful in 49s
Go Build Multi-Platform / build (arm, linux) (push) Successful in 58s
Go Build Multi-Platform / build (arm64, darwin) (push) Successful in 57s
Go Build Multi-Platform / build (arm64, windows) (push) Failing after 49s
Go Test Multi-Platform / Test (ubuntu-latest, arm64) (push) Successful in 53s
Run Gosec / tests (push) Successful in 1m25s
Go Revive Lint / lint (push) Successful in 48s
Go Test Multi-Platform / Test (ubuntu-latest, amd64) (push) Successful in 1m39s
Go Build Multi-Platform / build (arm64, linux) (push) Failing after 4m59s
Go Build Multi-Platform / build (amd64, linux) (push) Successful in 9m39s
Go Build Multi-Platform / build (arm64, freebsd) (push) Successful in 9m33s
Go Build Multi-Platform / build (arm, windows) (push) Successful in 9m35s
Go Build Multi-Platform / build (arm, freebsd) (push) Successful in 9m37s
Go Build Multi-Platform / build (amd64, darwin) (push) Successful in 9m42s
Go Build Multi-Platform / Create Release (push) Has been skipped

This commit is contained in:
2025-12-29 00:15:08 -06:00
parent 2fc9446687
commit 53e98c73af
10 changed files with 976 additions and 63 deletions

View File

@@ -0,0 +1,123 @@
package announce
import (
"bytes"
"sync"
"testing"
"git.quad4.io/Networks/Reticulum-Go/pkg/common"
"git.quad4.io/Networks/Reticulum-Go/pkg/identity"
)
type mockAnnounceHandler struct {
received bool
}
func (m *mockAnnounceHandler) AspectFilter() []string {
return nil
}
func (m *mockAnnounceHandler) ReceivedAnnounce(destinationHash []byte, announcedIdentity interface{}, appData []byte) error {
m.received = true
return nil
}
func (m *mockAnnounceHandler) ReceivePathResponses() bool {
return true
}
type mockInterface struct {
common.BaseInterface
sent bool
}
func (m *mockInterface) Send(data []byte, address string) error {
m.sent = true
return nil
}
func (m *mockInterface) GetBandwidthAvailable() bool {
return true
}
func (m *mockInterface) IsEnabled() bool {
return true
}
func TestNewAnnounce(t *testing.T) {
id, _ := identity.New()
destHash := make([]byte, 16)
config := &common.ReticulumConfig{}
ann, err := New(id, destHash, "testapp", []byte("appdata"), false, config)
if err != nil {
t.Fatalf("New failed: %v", err)
}
if ann == nil {
t.Fatal("New returned nil")
}
if !bytes.Equal(ann.destinationHash, destHash) {
t.Error("Destination hash doesn't match")
}
}
func TestCreateAndHandleAnnounce(t *testing.T) {
id, _ := identity.New()
destHash := make([]byte, 16)
config := &common.ReticulumConfig{}
ann, _ := New(id, destHash, "testapp", []byte("appdata"), false, config)
packet := ann.CreatePacket()
handler := &mockAnnounceHandler{}
ann.RegisterHandler(handler)
err := ann.HandleAnnounce(packet)
if err != nil {
t.Fatalf("HandleAnnounce failed: %v", err)
}
if !handler.received {
t.Error("Handler did not receive announce")
}
}
func TestPropagate(t *testing.T) {
id, _ := identity.New()
destHash := make([]byte, 16)
config := &common.ReticulumConfig{}
ann, _ := New(id, destHash, "testapp", []byte("appdata"), false, config)
iface := &mockInterface{}
iface.Name = "testiface"
iface.Online = true
iface.Enabled = true
err := ann.Propagate([]common.NetworkInterface{iface})
if err != nil {
t.Fatalf("Propagate failed: %v", err)
}
if !iface.sent {
t.Error("Packet was not sent on interface")
}
}
func TestHandlerRegistration(t *testing.T) {
ann := &Announce{
mutex: &sync.RWMutex{},
}
handler := &mockAnnounceHandler{}
ann.RegisterHandler(handler)
if len(ann.handlers) != 1 {
t.Errorf("Expected 1 handler, got %d", len(ann.handlers))
}
ann.DeregisterHandler(handler)
if len(ann.handlers) != 0 {
t.Errorf("Expected 0 handlers, got %d", len(ann.handlers))
}
}