2022-01-15 08:07:00 +00:00
|
|
|
package databag
|
2022-01-11 17:36:16 +00:00
|
|
|
|
2022-01-12 07:04:27 +00:00
|
|
|
import (
|
2022-07-22 19:28:14 +00:00
|
|
|
"databag/internal/store"
|
|
|
|
"os"
|
|
|
|
"testing"
|
2022-01-12 07:04:27 +00:00
|
|
|
)
|
2022-01-11 17:36:16 +00:00
|
|
|
|
2022-01-15 08:07:00 +00:00
|
|
|
func TestMain(m *testing.M) {
|
2022-01-12 07:04:27 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
// SetHideLog(true)
|
|
|
|
SetKeySize(2048)
|
|
|
|
os.Remove("databag.db")
|
|
|
|
os.RemoveAll("testdata")
|
|
|
|
os.RemoveAll("testscripts")
|
2022-02-28 22:59:29 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
store.SetPath("databag.db")
|
|
|
|
if err := os.Mkdir("testdata", os.ModePerm); err != nil {
|
|
|
|
panic("failed to create testdata path")
|
|
|
|
}
|
|
|
|
if err := os.Mkdir("testscripts", os.ModePerm); err != nil {
|
|
|
|
panic("failed to create testscripts path")
|
|
|
|
}
|
|
|
|
script := []byte("#!/bin/bash\n\ncp $1 $2\n")
|
|
|
|
if err := os.WriteFile("testscripts/transform_copy.sh", script, 0555); err != nil {
|
|
|
|
panic("failed to create P01 script")
|
|
|
|
}
|
2022-01-15 08:07:00 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
r, w, _ := NewRequest("GET", "/admin/status", nil)
|
|
|
|
GetNodeStatus(w, r)
|
|
|
|
var available bool
|
|
|
|
if ReadResponse(w, &available) != nil {
|
|
|
|
panic("server not claimable")
|
|
|
|
}
|
2022-01-11 17:36:16 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
// claim server
|
|
|
|
r, w, _ = NewRequest("PUT", "/admin/status?token=pass", nil)
|
|
|
|
SetNodeStatus(w, r)
|
|
|
|
if ReadResponse(w, nil) != nil {
|
|
|
|
panic("failed to claim server")
|
|
|
|
}
|
2022-01-12 07:16:08 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
// config data path
|
|
|
|
scripts := &store.Config{ConfigID: CNFScriptPath, StrValue: "./testscripts"}
|
|
|
|
if err := store.DB.Save(scripts).Error; err != nil {
|
|
|
|
panic("failed to configure scripts path")
|
|
|
|
}
|
2022-03-01 08:28:36 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
// config data path
|
|
|
|
path := &store.Config{ConfigID: CNFAssetPath, StrValue: "./testdata"}
|
|
|
|
if err := store.DB.Save(path).Error; err != nil {
|
|
|
|
panic("failed to configure data path")
|
|
|
|
}
|
2022-02-28 22:59:29 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
// config server
|
|
|
|
config := NodeConfig{Domain: "databag.coredb.org", AccountLimit: 1024, OpenAccess: true, AccountStorage: 4096}
|
|
|
|
r, w, _ = NewRequest("PUT", "/admin/config?token=pass", &config)
|
|
|
|
SetNodeConfig(w, r)
|
|
|
|
if ReadResponse(w, nil) != nil {
|
|
|
|
panic("failed to set config")
|
|
|
|
}
|
2022-01-15 05:27:43 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
// check config
|
|
|
|
r, w, _ = NewRequest("GET", "/admin/config?token=pass", nil)
|
|
|
|
GetNodeConfig(w, r)
|
|
|
|
var check NodeConfig
|
|
|
|
if ReadResponse(w, &check) != nil {
|
|
|
|
panic("failed to get node config")
|
|
|
|
}
|
|
|
|
if check.Domain != "databag.coredb.org" {
|
|
|
|
panic("failed to set config domain")
|
|
|
|
}
|
|
|
|
if check.AccountLimit != 1024 {
|
|
|
|
panic("failed to set account limit")
|
|
|
|
}
|
|
|
|
if check.OpenAccess != true {
|
|
|
|
panic("failed to set open access")
|
|
|
|
}
|
|
|
|
if check.AccountStorage != 4096 {
|
|
|
|
panic("failed to set account storage")
|
|
|
|
}
|
2022-01-17 07:00:08 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
go SendNotifications()
|
2022-01-27 19:45:01 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
m.Run()
|
2022-01-27 19:45:01 +00:00
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
ExitNotifications()
|
2022-01-17 07:00:08 +00:00
|
|
|
}
|