github.com/fozzysec/SiaPrime@v0.0.0-20190612043147-66c8e8d11fe3/siatest/dir.go (about) 1 package siatest 2 3 import ( 4 "os" 5 "path/filepath" 6 ) 7 8 var ( 9 // SiaTestingDir is the directory that contains all of the files and 10 // folders created during testing. 11 SiaTestingDir = filepath.Join(os.TempDir(), "SiaTesting") 12 ) 13 14 // TestDir joins the provided directories and prefixes them with the Sia 15 // testing directory, removing any files or directories that previously existed 16 // at that location. 17 func TestDir(dirs ...string) string { 18 path := filepath.Join(SiaTestingDir, "siatest", filepath.Join(dirs...)) 19 err := os.RemoveAll(path) 20 if err != nil { 21 panic(err) 22 } 23 return path 24 } 25 26 // siatestTestDir creates a testing directory for tests within the siatest 27 // module. 28 func siatestTestDir(testName string) string { 29 path := TestDir("siatest", testName) 30 if err := os.MkdirAll(path, 0777); err != nil { 31 panic(err) 32 } 33 return path 34 } 35 36 // filesDir returns the path to the files directory of the TestNode. The files 37 // directory is where new files are stored before being uploaded. 38 func (tn *TestNode) filesDir() string { 39 path := filepath.Join(tn.Dir, "files") 40 if err := os.MkdirAll(path, 0777); err != nil { 41 panic(err) 42 } 43 return path 44 } 45 46 // downloadsDir returns the path to the download directory of the TestNode. 47 func (tn *TestNode) downloadsDir() string { 48 path := filepath.Join(tn.Dir, "downloads") 49 if err := os.MkdirAll(path, 0777); err != nil { 50 panic(err) 51 } 52 return path 53 }