forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/faucet/main: replace faucet node datadir s/MultiFaucet/CoreFaucet/ (
ethereum#279) Use datadir migration logic to rename directory if exists.
- Loading branch information
Showing
2 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestMigrateFaucetDirectory(t *testing.T) { | ||
hardToCollideName := fmt.Sprintf("faucet-migration-test-datadir-%d", time.Now().UnixNano()) | ||
tempDir := filepath.Join(os.TempDir(), hardToCollideName) | ||
defer func() { | ||
os.RemoveAll(tempDir) | ||
}() | ||
|
||
faucetDataDir := filepath.Join(tempDir, "mychain") | ||
oldFaucetNodeDataDir := filepath.Join(faucetDataDir, multiFaucetNodeName) | ||
|
||
if err := os.MkdirAll(oldFaucetNodeDataDir, os.ModePerm); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
filepath.Walk(faucetDataDir, func(path string, info os.FileInfo, err error) error { | ||
t.Logf("%s", path) | ||
return nil | ||
}) | ||
|
||
if err := migrateFaucetDirectory(faucetDataDir); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
expected := filepath.Join(faucetDataDir, coreFaucetNodeName) | ||
d, err := os.Stat(expected) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !d.IsDir() { | ||
t.Fatal("non-directory") | ||
} | ||
filepath.Walk(faucetDataDir, func(path string, info os.FileInfo, err error) error { | ||
t.Logf("%s", path) | ||
return nil | ||
}) | ||
} |