-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
205 lines (147 loc) · 3.46 KB
/
main_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Main test (Integration)
package main
import (
"errors"
"os"
"path"
"runtime"
"sync"
"testing"
child_process_manager "github.com/AgustinSRG/go-child-process-manager"
"github.com/gorilla/mux"
)
var vaultMutex = &sync.Mutex{}
var testVaultInitialized = false
var testVaultKey []byte
var apiRouter *mux.Router
func ErrorMismatch(propName string, val string, expectedVal string) error {
return errors.New("Value mismatch. Expected '" + expectedVal + "' but found '" + val + "' for " + propName)
}
func InitializeTestVault() error {
vaultMutex.Lock()
defer vaultMutex.Unlock()
if testVaultInitialized {
return nil
}
os.RemoveAll("test-vault") // Remove test vault before starting
err := child_process_manager.InitializeChildProcessManager()
if err != nil {
return err
}
ffmpegPath := os.Getenv("FFMPEG_PATH")
if ffmpegPath == "" {
if runtime.GOOS == "windows" {
ffmpegPath = "C:\\\\ffmpeg\\bin\\ffmpeg.exe"
} else {
ffmpegPath = "/usr/bin/ffmpeg"
}
}
ffprobePath := os.Getenv("FFPROBE_PATH")
if ffprobePath == "" {
if runtime.GOOS == "windows" {
ffprobePath = "C:\\\\ffmpeg\\bin\\ffprobe.exe"
} else {
ffprobePath = "/usr/bin/ffprobe"
}
}
SetFFMPEGBinaries(ffmpegPath, ffprobePath) // Set FFMPEG paths
if os.Getenv("LOG_DEBUG") == "YES" {
SetDebugLogEnabled(true) // Log debug mode
}
if os.Getenv("LOG_REQUESTS") == "YES" {
SetRequestLogEnabled(true) // Log requests
}
SetTempFilesPath(path.Join("test-vault", "temp"))
ClearTemporalFilesPath()
vault := Vault{}
err = vault.Initialize("test-vault", 2)
if err != nil {
return err
}
testVaultInitialized = true
GLOBAL_VAULT = &vault
SetUnencryptedTempFilesPath("temp")
ClearUnencryptedTempFilesPath()
apiRouter = RunHTTPServer("", "", true)
initialUser := os.Getenv("VAULT_INITIAL_USER")
if initialUser == "" {
initialUser = VAULT_DEFAULT_USER
}
initialPassword := os.Getenv("VAULT_INITIAL_PASSWORD")
if initialPassword == "" {
initialPassword = VAULT_DEFAULT_PASSWORD
}
key, _, err := vault.credentials.UnlockVault(initialUser, initialPassword)
if err != nil {
return err
}
testVaultKey = key
return nil
}
func TestAPIIntegration(t *testing.T) {
server, err := GetTestServer()
if err != nil {
t.Error(err)
return
}
defer server.Close()
// Login
session, _, err := LoginTest(server)
if err != nil {
t.Error(err)
return
}
// API tests
wg := sync.WaitGroup{}
wg.Add(1)
t.Run("Account API", func(t *testing.T) {
Account_API_Test(server, session, t)
wg.Done()
})
wg.Add(1)
t.Run("Admin API", func(t *testing.T) {
Admin_API_Test(server, session, t)
wg.Done()
})
wg.Add(1)
t.Run("Media API", func(t *testing.T) {
Media_API_Test(server, session, t)
wg.Done()
})
wg.Add(1)
t.Run("Tags API", func(t *testing.T) {
Tags_API_Test(server, session, t)
wg.Done()
})
wg.Add(1)
t.Run("Search API", func(t *testing.T) {
Search_API_Test(server, session, t)
wg.Done()
})
wg.Add(1)
t.Run("Albums API", func(t *testing.T) {
Albums_API_Test(server, session, t)
wg.Done()
})
wg.Add(1)
t.Run("Config API", func(t *testing.T) {
Config_API_Test(server, session, t)
wg.Done()
})
// Wait for API tests to finish before logging out
wg.Wait()
// Wait for tasks to finish
wg2 := sync.WaitGroup{}
wg2.Add(1)
t.Run("Tasks API", func(t *testing.T) {
Tasks_API_Test(server, session, t)
wg2.Done()
})
wg2.Wait()
// Logout
err = LogoutTest(server, session)
if err != nil {
t.Error(err)
return
}
}