feat: add gomock testing

This commit is contained in:
Derrick Hammer 2024-01-08 00:16:32 -05:00
parent e39ea9e48f
commit 86da64fa41
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
8 changed files with 15 additions and 0 deletions

1
go.mod
View File

@ -4,6 +4,7 @@ go 1.20
require ( require (
github.com/emirpasic/gods v1.18.1 github.com/emirpasic/gods v1.18.1
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.6.0 github.com/google/go-cmp v0.6.0
github.com/multiformats/go-multibase v0.2.0 github.com/multiformats/go-multibase v0.2.0
github.com/vmihailenco/msgpack/v5 v5.4.1 github.com/vmihailenco/msgpack/v5 v5.4.1

View File

@ -1,5 +1,7 @@
package interfaces package interfaces
//go:generate mockgen -source=meta.go -destination=../mocks/interfaces/meta.go -package=interfaces
type Metadata interface { type Metadata interface {
ToJson() map[string]interface{} ToJson() map[string]interface{}
} }

View File

@ -8,6 +8,8 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
//go:generate mockgen -source=node.go -destination=../mocks/interfaces/node.go -package=interfaces
type Node interface { type Node interface {
Services() Services Services() Services
HashQueryRoutingTable() structs.Map HashQueryRoutingTable() structs.Map

View File

@ -7,6 +7,8 @@ import (
"net/url" "net/url"
) )
//go:generate mockgen -source=p2p.go -destination=../mocks/interfaces/p2p.go -package=interfaces
type P2PService interface { type P2PService interface {
Node() Node Node() Node
Peers() structs.Map Peers() structs.Map

View File

@ -1,5 +1,7 @@
package interfaces package interfaces
//go:generate mockgen -source=service.go -destination=../mocks/interfaces/service.go -package=interfaces
type Service interface { type Service interface {
Node() Node Node() Node
Start() error Start() error

View File

@ -1,5 +1,7 @@
package interfaces package interfaces
//go:generate mockgen -source=storage.go -destination=../mocks/interfaces/storage.go -package=interfaces
type StorageLocation interface { type StorageLocation interface {
BytesURL() string BytesURL() string
OutboardBytesURL() string OutboardBytesURL() string

View File

@ -2,6 +2,8 @@ package interfaces
import "github.com/vmihailenco/msgpack/v5" import "github.com/vmihailenco/msgpack/v5"
//go:generate mockgen -source=vote.go -destination=../mocks/interfaces/vote.go -package=interfaces
type NodeVotes interface { type NodeVotes interface {
msgpack.CustomEncoder msgpack.CustomEncoder
msgpack.CustomDecoder msgpack.CustomDecoder

View File

@ -6,6 +6,8 @@ import (
"github.com/vmihailenco/msgpack/v5" "github.com/vmihailenco/msgpack/v5"
) )
//go:generate mockgen -source=incoming_message.go -destination=../mocks/base/incoming_message.go -package=base
type IncomingMessage interface { type IncomingMessage interface {
HandleMessage(node interfaces.Node, peer net.Peer, verifyId bool) error HandleMessage(node interfaces.Node, peer net.Peer, verifyId bool) error
SetIncomingMessage(msg IncomingMessage) SetIncomingMessage(msg IncomingMessage)