test: use TestMain approach on protocol

This commit is contained in:
Derrick Hammer 2024-01-08 07:14:52 -05:00
parent 29cff7f368
commit a488cb806f
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 40 additions and 0 deletions

40
protocol/protocol_test.go Normal file
View File

@ -0,0 +1,40 @@
package protocol
import (
"git.lumeweb.com/LumeWeb/libs5-go/mocks/interfaces"
"git.lumeweb.com/LumeWeb/libs5-go/mocks/net"
"github.com/golang/mock/gomock"
"os"
"testing"
)
// Common resources
var (
mockCtrl *gomock.Controller
node *interfaces.MockNode
peer *net.MockPeer
services *interfaces.MockServices
p2p *interfaces.MockP2PService
)
// Setup function
func setup(t *testing.T) {
mockCtrl = gomock.NewController(t)
node = interfaces.NewMockNode(mockCtrl)
peer = net.NewMockPeer(mockCtrl)
services = interfaces.NewMockServices(mockCtrl)
p2p = interfaces.NewMockP2PService(mockCtrl)
}
// Teardown function
func teardown() {
mockCtrl.Finish()
// Other cleanup tasks
}
// TestMain function for setup and teardown
func TestMain(m *testing.M) {
code := m.Run()
teardown()
os.Exit(code)
}