-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_test.go
60 lines (48 loc) · 1.29 KB
/
server_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
package cmd
import (
"crypto/rand"
"encoding/hex"
"os"
"path/filepath"
"testing"
"time"
"github.com/devcows/share/lib"
"github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"
)
var (
testSettings lib.SettingsShare
configFile string
)
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 setup() {
configFile = TempFilename("config_", ".toml")
testSettings = lib.NewSettings()
testSettings.ShareDaemon.DatabaseFilePath = TempFilename("db_", ".db")
err := lib.CreateConfigFile(configFile, testSettings)
if err != nil {
panic(err)
}
}
func shutdown() {}
func TestMain(m *testing.M) {
setup()
code := m.Run()
shutdown()
os.Exit(code)
}
func TestExecuteServerCmd(t *testing.T) {
err := lib.InitSettings(configFile, &testSettings)
assert.Nil(t, err, GetErrorMessage(err))
err = lib.InitDB(testSettings)
assert.Nil(t, err, GetErrorMessage(err))
server := lib.Server{UUID: uuid.NewV4().String(), Path: "MyString", ListIps: []string{"1", "2"}, CreatedAt: time.Now()}
err = lib.StoreServer(server)
assert.Nil(t, err, GetErrorMessage(err))
err = runServerCmd(configFile, &testSettings)
assert.Nil(t, err, GetErrorMessage(err))
}