mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
This commit is being cherry-picked from upstream btcd and has been modified to integrate with dcrd by Dave Collins.
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
// Copyright (c) 2016 The btcsuite developers
|
|
// Copyright (c) 2016 The Decred developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"testing"
|
|
)
|
|
|
|
var (
|
|
rpcuserRegexp = regexp.MustCompile("(?m)^rpcuser=.+$")
|
|
rpcpassRegexp = regexp.MustCompile("(?m)^rpcpass=.+$")
|
|
)
|
|
|
|
func TestCreateDefaultConfigFile(t *testing.T) {
|
|
// Setup a temporary directory
|
|
tmpDir, err := ioutil.TempDir("", "dcrd")
|
|
if err != nil {
|
|
t.Fatalf("Failed creating a temporary directory: %v", err)
|
|
}
|
|
testpath := filepath.Join(tmpDir, "test.conf")
|
|
// Clean-up
|
|
defer func() {
|
|
os.Remove(testpath)
|
|
os.Remove(tmpDir)
|
|
}()
|
|
|
|
err = createDefaultConfigFile(testpath)
|
|
|
|
if err != nil {
|
|
t.Fatalf("Failed to create a default config file: %v", err)
|
|
}
|
|
|
|
content, err := ioutil.ReadFile(testpath)
|
|
if err != nil {
|
|
t.Fatalf("Failed to read generated default config file: %v", err)
|
|
}
|
|
|
|
if !rpcuserRegexp.Match(content) {
|
|
t.Error("Could not find rpcuser in generated default config file.")
|
|
}
|
|
|
|
if !rpcpassRegexp.Match(content) {
|
|
t.Error("Could not find rpcpass in generated default config file.")
|
|
}
|
|
}
|