From 86da64fa419166f9df8ed56cc101f37e07b0a463 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 8 Jan 2024 00:16:32 -0500 Subject: [PATCH] feat: add gomock testing --- go.mod | 1 + interfaces/meta.go | 2 ++ interfaces/node.go | 2 ++ interfaces/p2p.go | 2 ++ interfaces/service.go | 2 ++ interfaces/storage.go | 2 ++ interfaces/vote.go | 2 ++ protocol/base/base.go | 2 ++ 8 files changed, 15 insertions(+) diff --git a/go.mod b/go.mod index 75eacc7..96fb656 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.20 require ( github.com/emirpasic/gods v1.18.1 + github.com/golang/mock v1.6.0 github.com/google/go-cmp v0.6.0 github.com/multiformats/go-multibase v0.2.0 github.com/vmihailenco/msgpack/v5 v5.4.1 diff --git a/interfaces/meta.go b/interfaces/meta.go index 82589a1..38253ab 100644 --- a/interfaces/meta.go +++ b/interfaces/meta.go @@ -1,5 +1,7 @@ package interfaces +//go:generate mockgen -source=meta.go -destination=../mocks/interfaces/meta.go -package=interfaces + type Metadata interface { ToJson() map[string]interface{} } diff --git a/interfaces/node.go b/interfaces/node.go index 26509bd..cbb8000 100644 --- a/interfaces/node.go +++ b/interfaces/node.go @@ -8,6 +8,8 @@ import ( "go.uber.org/zap" ) +//go:generate mockgen -source=node.go -destination=../mocks/interfaces/node.go -package=interfaces + type Node interface { Services() Services HashQueryRoutingTable() structs.Map diff --git a/interfaces/p2p.go b/interfaces/p2p.go index d44ef47..b0a2520 100644 --- a/interfaces/p2p.go +++ b/interfaces/p2p.go @@ -7,6 +7,8 @@ import ( "net/url" ) +//go:generate mockgen -source=p2p.go -destination=../mocks/interfaces/p2p.go -package=interfaces + type P2PService interface { Node() Node Peers() structs.Map diff --git a/interfaces/service.go b/interfaces/service.go index 8d8a8bd..ba0e61e 100644 --- a/interfaces/service.go +++ b/interfaces/service.go @@ -1,5 +1,7 @@ package interfaces +//go:generate mockgen -source=service.go -destination=../mocks/interfaces/service.go -package=interfaces + type Service interface { Node() Node Start() error diff --git a/interfaces/storage.go b/interfaces/storage.go index 6552b3f..31d7051 100644 --- a/interfaces/storage.go +++ b/interfaces/storage.go @@ -1,5 +1,7 @@ package interfaces +//go:generate mockgen -source=storage.go -destination=../mocks/interfaces/storage.go -package=interfaces + type StorageLocation interface { BytesURL() string OutboardBytesURL() string diff --git a/interfaces/vote.go b/interfaces/vote.go index 83081e3..dbfb1c1 100644 --- a/interfaces/vote.go +++ b/interfaces/vote.go @@ -2,6 +2,8 @@ package interfaces import "github.com/vmihailenco/msgpack/v5" +//go:generate mockgen -source=vote.go -destination=../mocks/interfaces/vote.go -package=interfaces + type NodeVotes interface { msgpack.CustomEncoder msgpack.CustomDecoder diff --git a/protocol/base/base.go b/protocol/base/base.go index 98468c6..d1ac677 100644 --- a/protocol/base/base.go +++ b/protocol/base/base.go @@ -6,6 +6,8 @@ import ( "github.com/vmihailenco/msgpack/v5" ) +//go:generate mockgen -source=incoming_message.go -destination=../mocks/base/incoming_message.go -package=base + type IncomingMessage interface { HandleMessage(node interfaces.Node, peer net.Peer, verifyId bool) error SetIncomingMessage(msg IncomingMessage)