-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathio_test.go
92 lines (68 loc) · 1.72 KB
/
io_test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"net/http"
"os"
"runtime"
"testing"
)
const TestDir = "./test_data"
func TestCreateFile(t *testing.T) {
tmb := &Thumbnail{}
// thumbnailsDir := "./test_data"
_ = createFolder(TestDir)
thumbnailsName := TestDir[2:] + "/thumbnail_" + setNameDigit(tmb.fileName) + ".jpg"
file, err := createFile(thumbnailsName)
if err != nil {
t.Error("Wrong created file!")
}
file.Close()
os.Remove("./" + thumbnailsName)
}
func TestCreateWrongDirectory(t *testing.T) {
var thumbnailsDir string
osName := runtime.GOOS
if osName == "windows" {
thumbnailsDir = "/<"
} else if osName == "linux" {
thumbnailsDir = ""
}
err := createFolder(thumbnailsDir)
if err == nil {
t.Error("Expected nil return!")
}
}
func TestCreateFileWrong(t *testing.T) {
// thumbnailsDir := "./test_data"
_ = createFolder(TestDir)
var thumbnailsName string
osName := runtime.GOOS
if osName == "windows" {
thumbnailsName = TestDir[2:] + "/<"
} else if osName == "linux" {
thumbnailsName = "/"
}
file, err := createFile(thumbnailsName)
file.Close()
defer os.Remove("./" + thumbnailsName)
if err == nil {
t.Error("incorrect file name. Must be nil return!")
}
}
func TestWriteFile(t *testing.T) {
file, _ := os.Create(TestDir + "/thumbnail_test2.jpg")
defer file.Close()
defer os.Remove(TestDir + "/thumbnail_test2.jpg")
resp, err := http.Get("https://www.youtube.com/watch?v=N2wJQSBx5i4")
if writeFile(file, resp) != nil {
t.Errorf("Write file failed %v\n", err)
}
resp.Body.Close()
}
func TestWriteFileWrong(t *testing.T) {
resp, _ := http.Get("https://www.youtube.com/watch?v=N2wJQSBx5i4")
err := writeFile(nil, resp)
if err == nil {
t.Errorf("Write file failed %v\n", err)
}
resp.Body.Close()
}