github.com/celestiaorg/celestia-node@v0.15.0-beta.1/nodebuilder/p2p/module_test.go (about)

     1  package p2p
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/ipfs/go-datastore"
     8  	ds_sync "github.com/ipfs/go-datastore/sync"
     9  	"go.uber.org/fx"
    10  	"go.uber.org/fx/fxtest"
    11  
    12  	"github.com/celestiaorg/celestia-node/libs/keystore"
    13  	"github.com/celestiaorg/celestia-node/nodebuilder/node"
    14  )
    15  
    16  func testModule(tp node.Type) fx.Option {
    17  	cfg := DefaultConfig(tp)
    18  	// TODO(@Wondertan): Most of these can be deduplicated
    19  	//  by moving Store into the modnode and introducing there a TestModNode module
    20  	//  that testers would import
    21  	return fx.Options(
    22  		fx.NopLogger,
    23  		ConstructModule(tp, &cfg),
    24  		fx.Provide(context.Background),
    25  		fx.Supply(Private),
    26  		fx.Supply(Bootstrappers{}),
    27  		fx.Supply(tp),
    28  		fx.Provide(keystore.NewMapKeystore),
    29  		fx.Supply(fx.Annotate(ds_sync.MutexWrap(datastore.NewMapDatastore()), fx.As(new(datastore.Batching)))),
    30  	)
    31  }
    32  
    33  func TestModuleBuild(t *testing.T) {
    34  	var test = []struct {
    35  		tp node.Type
    36  	}{
    37  		{tp: node.Bridge},
    38  		{tp: node.Full},
    39  		{tp: node.Light},
    40  	}
    41  
    42  	for _, tt := range test {
    43  		t.Run(tt.tp.String(), func(t *testing.T) {
    44  			app := fxtest.New(t, testModule(tt.tp))
    45  			app.RequireStart()
    46  			app.RequireStop()
    47  		})
    48  	}
    49  }
    50  
    51  func TestModuleBuild_WithMetrics(t *testing.T) {
    52  	var test = []struct {
    53  		tp node.Type
    54  	}{
    55  		{tp: node.Full},
    56  		{tp: node.Bridge},
    57  		{tp: node.Light},
    58  	}
    59  
    60  	for _, tt := range test {
    61  		t.Run(tt.tp.String(), func(t *testing.T) {
    62  			app := fxtest.New(t, testModule(tt.tp), WithMetrics())
    63  			app.RequireStart()
    64  			app.RequireStop()
    65  		})
    66  	}
    67  }