MCPcopy Create free account
hub / github.com/CPChain/chain / TestNodeUsedDataDir

Function TestNodeUsedDataDir

node/node_test.go:64–90  ·  view source on GitHub ↗

Tests that if the data dir is already in use, an appropriate error is returned.

(t *testing.T)

Source from the content-addressed store, hash-verified

62
63// Tests that if the data dir is already in use, an appropriate error is returned.
64func TestNodeUsedDataDir(t *testing.T) {
65 // Create a temporary folder to use as the data directory
66 dir, err := ioutil.TempDir("", "")
67 if err != nil {
68 t.Fatalf("failed to create temporary data directory: %v", err)
69 }
70 defer os.RemoveAll(dir)
71
72 // Create a new node based on the data directory
73 original, err := New(&Config{DataDir: dir})
74 if err != nil {
75 t.Fatalf("failed to create original protocol stack: %v", err)
76 }
77 if err := original.Start(); err != nil {
78 t.Fatalf("failed to start original protocol stack: %v", err)
79 }
80 defer original.Stop()
81
82 // Create a second node based on the same data directory and ensure failure
83 duplicate, err := New(&Config{DataDir: dir})
84 if err != nil {
85 t.Fatalf("failed to create duplicate protocol stack: %v", err)
86 }
87 if err := duplicate.Start(); err != ErrDatadirUsed {
88 t.Fatalf("duplicate datadir failure mismatch: have %v, want %v", err, ErrDatadirUsed)
89 }
90}
91
92// Tests whether services can be registered and duplicates caught.
93func TestServiceRegistry(t *testing.T) {

Callers

nothing calls this directly

Calls 3

NewFunction · 0.70
StartMethod · 0.65
StopMethod · 0.65

Tested by

no test coverage detected