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

Function TestDatadirCreation

node/config_test.go:20–50  ·  view source on GitHub ↗

Tests that datadirs can be successfully created, be them manually configured ones or automatically generated temporary ones.

(t *testing.T)

Source from the content-addressed store, hash-verified

18// Tests that datadirs can be successfully created, be them manually configured
19// ones or automatically generated temporary ones.
20func TestDatadirCreation(t *testing.T) {
21 // Create a temporary data dir and check that it can be used by a node
22 dir, err := ioutil.TempDir("", "")
23 if err != nil {
24 t.Fatalf("failed to create manual data dir: %v", err)
25 }
26 defer os.RemoveAll(dir)
27
28 if _, err := New(&Config{DataDir: dir}); err != nil {
29 t.Fatalf("failed to create stack with existing datadir: %v", err)
30 }
31 // Generate a long non-existing datadir path and check that it gets created by a node
32 dir = filepath.Join(dir, "a", "b", "c", "d", "e", "f")
33 if _, err := New(&Config{DataDir: dir}); err != nil {
34 t.Fatalf("failed to create stack with creatable datadir: %v", err)
35 }
36 if _, err := os.Stat(dir); err != nil {
37 t.Fatalf("freshly created datadir not accessible: %v", err)
38 }
39 // Verify that an impossible datadir fails creation
40 file, err := ioutil.TempFile("", "")
41 if err != nil {
42 t.Fatalf("failed to create temporary file: %v", err)
43 }
44 defer os.Remove(file.Name())
45
46 dir = filepath.Join(file.Name(), "invalid/path")
47 if _, err := New(&Config{DataDir: dir}); err == nil {
48 t.Fatalf("protocol stack created with an invalid datadir")
49 }
50}
51
52// Tests that IPC paths are correctly resolved to valid endpoints of different
53// platforms.

Callers

nothing calls this directly

Calls 3

NewFunction · 0.70
RemoveMethod · 0.45
NameMethod · 0.45

Tested by

no test coverage detected