-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings_test.go
98 lines (74 loc) · 2.25 KB
/
settings_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
93
94
95
96
97
98
package lib
import (
"crypto/rand"
"encoding/hex"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
func TempFilename(prefix string, extension string) string {
randBytes := make([]byte, 16)
rand.Read(randBytes)
return filepath.Join(os.TempDir(), prefix+hex.EncodeToString(randBytes)+extension)
}
func TestCreateConfigFile(t *testing.T) {
var testSettings SettingsShare
configFile := TempFilename("config_", ".toml")
err := CreateConfigFile(configFile, testSettings)
assert.Nil(t, err, GetErrorMessage(err))
_, err2 := os.Stat(configFile)
assert.False(t, os.IsNotExist(err2), "The config file: %s doesn't exists!", configFile)
}
func TestInitSettings(t *testing.T) {
var testSettings SettingsShare
testSettings = NewSettings()
testSettings.Daemon.DatabaseFilePath = TempFilename("db_", ".db")
configFile := TempFilename("config_", ".toml")
err := CreateConfigFile(configFile, testSettings)
assert.Nil(t, err, GetErrorMessage(err))
// Create
err = InitSettings(configFile, &testSettings)
assert.Nil(t, err, GetErrorMessage(err))
assert.NotNil(t, testSettings)
// LOAD
err = InitSettings(configFile, &testSettings)
assert.Nil(t, err, GetErrorMessage(err))
assert.NotNil(t, testSettings)
}
func TestNewSettings(t *testing.T) {
testSettings := NewSettings()
assert.NotNil(t, testSettings)
}
func TestConfigFolder(t *testing.T) {
pathConfigFolder := ConfigFolder()
assert.NotNil(t, pathConfigFolder)
assert.True(t, len(pathConfigFolder) > 0)
}
func TestConfigFile(t *testing.T) {
pathConfigFile := ConfigFile()
assert.NotNil(t, pathConfigFile)
assert.True(t, len(pathConfigFile) > 0)
}
func TestConfigFileSQLITE(t *testing.T) {
pathConfigDb := ConfigFileSQLITE()
assert.NotNil(t, pathConfigDb)
assert.True(t, len(pathConfigDb) > 0)
}
func TestConfigServerEndPoint(t *testing.T) {
testSettings := NewSettings()
endPoint := ConfigServerEndPoint(testSettings)
assert.NotNil(t, endPoint)
assert.True(t, len(endPoint) > 0)
}
func TestUserHomeDir(t *testing.T) {
listOs := []string{"linux", "windows", "darwin"}
for i := 0; i < len(listOs); i++ {
pathConfigUserDir := UserHomeDir(listOs[i])
assert.NotNil(t, pathConfigUserDir)
if listOs[i] == runtime.GOOS {
assert.True(t, len(pathConfigUserDir) > 0)
}
}
}