forked from yyoshiki41/go-radiko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.go
48 lines (38 loc) · 917 Bytes
/
testing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package radiko
import (
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"
)
const areaIDTokyo = "JP13"
var (
outsideJP bool
testdataDir string
)
func init() {
// Skip tests if outside Japan.
OUTSIDEJP := os.Getenv("GO_RADIKO_OUTSIDE_JP")
if len(OUTSIDEJP) > 0 {
outsideJP = true
}
GOPATH := os.Getenv("GOPATH")
testdataDir = filepath.Join(GOPATH, "src", "github.com/chikulla/go-radiko", "testdata")
}
// For skipping tests.
// radiko.jp restricts use from outside Japan.
func isOutsideJP() bool {
return outsideJP
}
// Should restore defaultHTTPClient if SetHTTPClient is called.
func teardownHTTPClient() {
SetHTTPClient(&http.Client{Timeout: defaultHTTPTimeout})
}
func createTestTempDir(t *testing.T) (string, func()) {
dir, err := ioutil.TempDir("", "test-go-radiko")
if err != nil {
t.Fatalf("Failed to create temp dir: %s", err)
}
return dir, func() { os.RemoveAll(dir) }
}