github.com/aergoio/aergo@v1.3.1/p2p/p2pmock/readme.txt (about)

     1  Examples to generate mock class
     2  
     3  1. with reflection (and no flag is allowed) : It can generate mock of outside of current source tree, but has drawback that cannot set output package. it must be followed by manual editing or other way to correct the package of generated mock class
     4  mockgen github.com/aergoio/aergo/p2p/p2pcommon HSHandlerFactory  > p2p/p2pmock/mock_hsfactory.go
     5  
     6  
     7  1-1. correct package using GNU sed
     8  mockgen github.com/libp2p/go-libp2p-core Host | gsed -e 's/^package mock_[a-zA-Z0-9_]\+/package p2pmock/g' > p2p/p2pmock/mock_host.go
     9  
    10  NOTE: There is no suitable common way to catch regexp + (match one or more) on multiple OS environment. On linux gnu sed, the flag to enable extended regxp is -r, but on macos bsd sed, it is -E.
    11  
    12  2. with flags : generate mocks of all interface in single file
    13  mockgen -source=p2p/p2pcommon/pool.go -package=p2pmock -destination=p2p/p2pmock/mock_peerfinder.go
    14  
    15  3. with flags others : can select the classes (exclude a class) in single file, setting class mapping is too tedious
    16  mockgen -source=p2p/p2pcommon/pool.go -mock_names=WaitingPeerManager=MockWaitingPeerManager  -package=p2pmock -destination=p2p/p2pmock/mock_peerfinder.go
    17  
    18  
    19  # Manually generated mock classes
    20  The generate decriptions of these mock objects are in p2p/p2pcommon/temptypes.go . So you can use such like `go generate ./p2p/p2pcommon/temptypes.go` command.
    21  
    22  # mock files which are not generated automatically by go generate ./p2p
    23  mockgen github.com/aergoio/aergo/consensus ConsensusAccessor,AergoRaftAccessor | gsed -e 's/^package mock_[a-zA-Z0-9_]\+/package p2pmock/g' > p2p/p2pmock/mock_consensus.go
    24  
    25  mockgen io Reader,ReadCloser,Writer,WriteCloser,ReadWriteCloser > p2p/p2pmock/mock_io.go | gsed -e 's/^package mock_[a-zA-Z0-9_]\+/package p2pmock/g'  > p2p/p2pmock/mock_io.go
    26  
    27  mockgen github.com/aergoio/aergo/types ChainAccessor | sed -e 's/^package mock_mock_[a-zA-Z0-9_]\+/package p2pmock/g' > ../p2pmock/mock_chainaccessor.go