gitlab.com/SiaPrime/SiaPrime@v1.4.1/node/templates_test.go (about)

     1  package node
     2  
     3  import (
     4  	"testing"
     5  
     6  	"gitlab.com/SiaPrime/SiaPrime/build"
     7  )
     8  
     9  // TestNew is a basic smoke test for New that uses all of the templates to
    10  // verify a working New function.
    11  func TestNew(t *testing.T) {
    12  	if testing.Short() {
    13  		t.SkipNow()
    14  	}
    15  
    16  	// Test AllModulesTemplate.
    17  	dir := build.TempDir("node", t.Name()+"-AllModulesTemplate")
    18  	n, err := New(AllModules(dir))
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  	if n.Gateway == nil {
    23  		t.Error("gateway not set correctly")
    24  	}
    25  	if n.ConsensusSet == nil {
    26  		t.Error("consensus set not set correctly")
    27  	}
    28  	if n.Explorer == nil {
    29  		// TODO: Add the explorer to the node package.
    30  		t.Log("Need to add the explorer to the SiaNode framework.")
    31  	}
    32  	if n.TransactionPool == nil {
    33  		t.Error("transaction pool not set correctly")
    34  	}
    35  	if n.Wallet == nil {
    36  		t.Error("wallet not set correctly")
    37  	}
    38  	if n.Host == nil {
    39  		t.Error("host not set correctly")
    40  	}
    41  	if n.Renter == nil {
    42  		t.Error("renter not set correctly")
    43  	}
    44  	if n.Miner == nil {
    45  		t.Error("miner not set correctly")
    46  	}
    47  	err = n.Close()
    48  	if err != nil {
    49  		t.Fatal(err)
    50  	}
    51  
    52  	// Test WalletTemplate.
    53  	dir = build.TempDir("node", t.Name()+"-WalletTemplate")
    54  	n, err = New(Wallet(dir))
    55  	if err != nil {
    56  		t.Fatal(err)
    57  	}
    58  	if n.Gateway == nil {
    59  		t.Error("gateway not set correctly")
    60  	}
    61  	if n.ConsensusSet == nil {
    62  		t.Error("consensus set not set correctly")
    63  	}
    64  	if n.Explorer != nil {
    65  		t.Error("explorer should not be created when using the wallet template")
    66  	}
    67  	if n.TransactionPool == nil {
    68  		t.Error("transaction pool not set correctly")
    69  	}
    70  	if n.Wallet == nil {
    71  		t.Error("wallet not set correctly")
    72  	}
    73  	if n.Host != nil {
    74  		t.Error("host should not be created when using the wallet template")
    75  	}
    76  	if n.Renter != nil {
    77  		t.Error("renter should not be created when using the wallet template")
    78  	}
    79  	if n.Miner != nil {
    80  		t.Error("miner should not be created when using the wallet template")
    81  	}
    82  	err = n.Close()
    83  	if err != nil {
    84  		t.Fatal(err)
    85  	}
    86  }