databag/net/server/internal/main_test.go

65 lines
1.4 KiB
Go
Raw Normal View History

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 (
"os"
2022-01-12 07:04:27 +00:00
"testing"
2022-01-12 21:12:40 +00:00
"databag/internal/store"
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
// SetHideLog(true)
2022-01-19 23:03:06 +00:00
SetKeySize(2048)
os.Remove("databag.db")
store.SetPath("databag.db")
2022-01-15 08:07:00 +00:00
2022-01-17 21:27:48 +00:00
r, w, _ := NewRequest("GET", "/admin/claimable", nil)
2022-01-15 08:07:00 +00:00
GetNodeClaimable(w, r)
2022-01-17 21:27:48 +00:00
var available bool
if ReadResponse(w, &available) != nil {
panic("server not claimable")
2022-01-12 07:04:27 +00:00
}
2022-01-11 17:36:16 +00:00
2022-01-17 22:25:39 +00:00
// claim server
r, w, _ = NewRequest("PUT", "/admin/claim", nil)
2022-01-17 21:27:48 +00:00
SetCredentials(r, "admin:pass");
2022-01-15 08:07:00 +00:00
SetNodeClaim(w, r)
2022-01-17 21:27:48 +00:00
if ReadResponse(w, nil) != nil {
panic("failed to claim server")
2022-01-12 07:16:08 +00:00
}
2022-01-17 22:25:39 +00:00
// config server
2022-01-15 08:07:00 +00:00
config := NodeConfig{Domain: "example.com", PublicLimit: 1024, AccountStorage: 4096}
2022-01-17 22:25:39 +00:00
r, w, _ = NewRequest("PUT", "/admin/config", &config)
2022-01-17 21:27:48 +00:00
SetBasicAuth(r, "admin:pass")
SetNodeConfig(w, r)
if ReadResponse(w, nil) != nil {
panic("failed to set config")
2022-01-12 21:12:40 +00:00
}
2022-01-15 05:27:43 +00:00
2022-01-17 22:25:39 +00:00
// check config
r, w, _ = NewRequest("GET", "/admin/config", nil)
2022-01-17 21:27:48 +00:00
SetBasicAuth(r, "admin:pass")
GetNodeConfig(w, r)
2022-01-17 22:25:39 +00:00
var check NodeConfig
if ReadResponse(w, &check) != nil {
2022-01-15 08:07:00 +00:00
panic("failed to get node config")
2022-01-15 05:27:43 +00:00
}
2022-01-17 22:25:39 +00:00
if check.Domain != "example.com" {
2022-01-15 08:07:00 +00:00
panic("failed to set config domain");
2022-01-15 05:27:43 +00:00
}
2022-01-17 22:25:39 +00:00
if check.PublicLimit != 1024 {
2022-01-15 08:07:00 +00:00
panic("failed to set public limit");
2022-01-15 05:27:43 +00:00
}
2022-01-17 22:25:39 +00:00
if check.AccountStorage != 4096 {
2022-01-15 08:07:00 +00:00
panic("failed to set account storage");
2022-01-15 05:27:43 +00:00
}
2022-01-17 07:00:08 +00:00
2022-01-27 19:45:01 +00:00
go SendNotifications()
2022-01-17 22:25:39 +00:00
m.Run()
2022-01-27 19:45:01 +00:00
ExitNotifications()
2022-01-17 07:00:08 +00:00
}
2022-01-17 22:25:39 +00:00