-
Notifications
You must be signed in to change notification settings - Fork 4
/
options_test.go
79 lines (71 loc) · 2.03 KB
/
options_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
package syno_test // import jdel.org/go-syno/syno_test
import (
"bytes"
"log"
"os"
"path/filepath"
"testing"
syno "jdel.org/go-syno"
)
func TestOptionsGetOptions(t *testing.T) {
newOptions := syno.GetOptions()
if newOptions.PackagesDir != filepath.Join("tests", "packages") {
t.Errorf("Expected packages dir to be %s but got %s", filepath.Join("tests", "packages"), newOptions.PackagesDir)
}
if newOptions.CacheDir != filepath.Join("tests", "cache") {
t.Errorf("Expected cache dir to be %s but got %s", filepath.Join("tests", "cache"), newOptions.CacheDir)
}
if newOptions.ModelsFile != filepath.Join("tests", "cache", "models.yml") {
t.Errorf("Expected models file to be %s but got %s", filepath.Join("tests", "models.yml"), newOptions.ModelsFile)
}
if newOptions.Language != "enu" {
t.Errorf("Expected language to be %s but got %s", "enu", newOptions.Language)
}
if !newOptions.MD5 {
t.Errorf("Expected MD5 to be %t but got %t", true, newOptions.MD5)
}
}
func TestOptionsLogLevel(t *testing.T) {
cleanupModels(t)
var b bytes.Buffer
syno.SetLogLevel(syno.LogDebugLevel)
syno.SetLogOutput(&b)
defer func() {
log.SetOutput(os.Stderr)
}()
syno.GetModels(false)
if len(b.String()) == 0 {
t.Errorf("Expecting loglevel Debug to write to buffer but it didn't")
}
}
func TestOptionsSetOptions(t *testing.T) {
previousOptions := *o
defer func() {
syno.SetOptions(previousOptions)
}()
syno.SetOptions(syno.Options{
CacheDir: "c",
PackagesDir: "p",
ModelsFile: "m",
Language: "l",
MD5: false,
})
if o.CacheDir != "c" {
t.Errorf("Expected cache dir to be c but got %s", o.CacheDir)
}
if o.PackagesDir != "p" {
t.Errorf("Expected packages dir to be but got %s", o.PackagesDir)
}
if o.ModelsFile != "m" {
t.Errorf("Expected models file to be m but got %s", o.ModelsFile)
}
if o.Language != "l" {
t.Errorf("Expected language to be l but got %s", o.Language)
}
if o.MD5 {
t.Errorf("Expected MD5 to be %t but got %t", false, o.MD5)
}
}
func TestOptoinsFinished(t *testing.T) {
cleanupModels(t)
}