Moves testdata in test/data
This commit is contained in:
29
data_test.go
29
data_test.go
@@ -85,7 +85,7 @@ func GetCsvData() *bytes.Buffer {
|
||||
|
||||
func init() {
|
||||
start := time.Now()
|
||||
albumsPath := filepath.Join("testdata", "albums.json")
|
||||
albumsPath := filepath.Join("test", "data", "albums.json")
|
||||
f, err := os.Open(albumsPath)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Could not open '%s': %s", albumsPath, err))
|
||||
@@ -100,9 +100,34 @@ func init() {
|
||||
log.Printf("loaded test data in %s", time.Since(start))
|
||||
start = time.Now()
|
||||
dv := diskv.New(diskv.Options{
|
||||
BasePath: filepath.Join("testdata", "web-cache"),
|
||||
BasePath: filepath.Join("test", "data", "web-cache"),
|
||||
CacheSizeMax: 100 * 1024 * 1024, // 100MB
|
||||
})
|
||||
testGetter = httpcache.NewTransport(diskcache.NewWithDiskv(dv)).Client()
|
||||
log.Printf("loaded httpcache in %s", time.Since(start))
|
||||
|
||||
jsonInfo, err := os.Stat(albumsPath)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Could not stat %s: %s", albumsPath, err))
|
||||
}
|
||||
csvPath := filepath.Join("test", "data", "albums.csv")
|
||||
csvInfo, err := os.Stat(csvPath)
|
||||
if err != nil && os.IsNotExist(err) == false {
|
||||
panic(fmt.Sprintf("Could not stat %s: %s", csvPath, err))
|
||||
}
|
||||
|
||||
if err == nil && csvInfo.ModTime().After(jsonInfo.ModTime()) == true {
|
||||
// no need to update the file
|
||||
return
|
||||
}
|
||||
newFile, err := os.Create(csvPath)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Could not create %s: %s", csvPath, err))
|
||||
}
|
||||
defer closeOrPanic(newFile, csvPath)
|
||||
_, err = io.Copy(newFile, GetCsvData())
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Could not save csv data: %s", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user