-
Notifications
You must be signed in to change notification settings - Fork 4
/
models_internal_test.go
84 lines (75 loc) · 1.8 KB
/
models_internal_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
package syno // import jdel.org/go-syno/syno
import (
"os"
"testing"
)
var defaultModels Models
func init() {
defaultModels = Models{
&Model{
Name: "Spaghetti",
},
&Model{
Name: "Penne",
},
&Model{
Name: "Farfalle",
},
&Model{
Name: "Papardelle",
},
}
}
func cleanupModels(t *testing.T) {
if err := os.RemoveAll(o.ModelsFile); err != nil {
t.Skipf("Cannot cleanup %s", o.ModelsFile)
}
}
func TestModelsGetFromFile(t *testing.T) {
cleanupModels(t)
if err := defaultModels.SaveModelsFile(); err != nil {
t.Error(err)
}
if m, err := getModelsFromModelsFile(); err != nil {
t.Error(err)
} else if len(m) != len(defaultModels) {
t.Errorf("Expected to read %d models from file but fot %d", len(defaultModels), len(m))
}
}
func TestModelsGetFromFileReadError(t *testing.T) {
cleanupModels(t)
if err := defaultModels.SaveModelsFile(); err != nil {
t.Error(err)
}
if err := os.RemoveAll(o.ModelsFile); err != nil {
t.Skipf("Could not delete file %s to prepare for test", o.ModelsFile)
}
if _, err := getModelsFromModelsFile(); err == nil {
t.Error("Expected a read error")
}
}
// func TestModelsGetFromFileBadYML(t *testing.T) {
// cleanupModels(t)
// f, err := os.OpenFile(o.ModelsFile, os.O_CREATE|os.O_WRONLY, 0755)
// defer f.Close()
// if err != nil {
// t.Skipf("Could not write file %s to prepare for test", o.ModelsFile)
// }
// f.Write([]byte(":"))
// f.Close()
// m, err := getModelsFromModelsFile()
// fmt.Println(m)
// if err == nil {
// t.Error("Expected a parsing error")
// }
// }
func TestModelsGetFromInternet(t *testing.T) {
if m, err := getModelsFromInternet(); err != nil {
t.Error(err)
} else if len(m) == 0 {
t.Error("Expected at least one model from the internet but got 0")
}
}
func TestModelsFinished(t *testing.T) {
cleanupModels(t)
}