github.com/dashpay/godash@v0.0.0-20160726055534-e038a21e0e3d/config_test.go (about) 1 package main 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "regexp" 8 "testing" 9 ) 10 11 var ( 12 rpcuserRegexp = regexp.MustCompile("(?m)^rpcuser=.+$") 13 rpcpassRegexp = regexp.MustCompile("(?m)^rpcpass=.+$") 14 ) 15 16 func TestCreateDefaultConfigFile(t *testing.T) { 17 // Setup a temporary directory 18 tmpDir, err := ioutil.TempDir("", "btcd") 19 if err != nil { 20 t.Fatalf("Failed creating a temporary directory: %v", err) 21 } 22 testpath := filepath.Join(tmpDir, "test.conf") 23 // Clean-up 24 defer func() { 25 os.Remove(testpath) 26 os.Remove(tmpDir) 27 }() 28 29 err = createDefaultConfigFile(testpath) 30 31 if err != nil { 32 t.Fatalf("Failed to create a default config file: %v", err) 33 } 34 35 content, err := ioutil.ReadFile(testpath) 36 if err != nil { 37 t.Fatalf("Failed to read generated default config file: %v", err) 38 } 39 40 if !rpcuserRegexp.Match(content) { 41 t.Error("Could not find rpcuser in generated default config file.") 42 } 43 44 if !rpcpassRegexp.Match(content) { 45 t.Error("Could not find rpcpass in generated default config file.") 46 } 47 }