2022-01-12 07:04:27 +00:00
|
|
|
package main
|
2022-01-11 17:36:16 +00:00
|
|
|
|
2022-01-12 07:04:27 +00:00
|
|
|
import (
|
2022-01-12 21:12:40 +00:00
|
|
|
"strings"
|
2022-01-12 07:04:27 +00:00
|
|
|
"testing"
|
|
|
|
"net/http/httptest"
|
2022-01-12 07:16:08 +00:00
|
|
|
"encoding/base64"
|
2022-01-12 21:12:40 +00:00
|
|
|
"encoding/json"
|
2022-01-12 07:04:27 +00:00
|
|
|
app "databag/internal"
|
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-12 07:16:08 +00:00
|
|
|
func TestSetup(t *testing.T) {
|
2022-01-12 07:04:27 +00:00
|
|
|
|
|
|
|
store.SetPath("file::memory:?cache=shared");
|
2022-01-12 21:12:40 +00:00
|
|
|
//store.SetPath("databag.db");
|
2022-01-12 07:16:08 +00:00
|
|
|
Claimable(t);
|
|
|
|
Claim(t);
|
2022-01-12 21:12:40 +00:00
|
|
|
Config(t);
|
2022-01-12 07:16:08 +00:00
|
|
|
}
|
2022-01-12 07:04:27 +00:00
|
|
|
|
2022-01-12 07:16:08 +00:00
|
|
|
func Claimable(t *testing.T) {
|
2022-01-12 21:12:40 +00:00
|
|
|
r := httptest.NewRequest("GET", "/admin/claimable", nil)
|
2022-01-12 07:04:27 +00:00
|
|
|
w := httptest.NewRecorder()
|
2022-01-12 21:12:40 +00:00
|
|
|
app.GetNodeClaimable(w, r)
|
2022-01-12 07:04:27 +00:00
|
|
|
if w.Code != 200 {
|
2022-01-12 21:12:40 +00:00
|
|
|
t.Errorf("server not initially claimable")
|
2022-01-12 07:04:27 +00:00
|
|
|
}
|
2022-01-11 17:36:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-12 07:16:08 +00:00
|
|
|
func Claim(t *testing.T) {
|
|
|
|
auth := base64.StdEncoding.EncodeToString([]byte("admin:pass"))
|
2022-01-12 21:12:40 +00:00
|
|
|
r := httptest.NewRequest("PUT", "/admin/claim", nil)
|
2022-01-12 07:16:08 +00:00
|
|
|
r.Header.Add("Authorization","Basic " + auth)
|
|
|
|
w := httptest.NewRecorder()
|
2022-01-12 21:12:40 +00:00
|
|
|
app.SetNodeClaim(w, r)
|
2022-01-12 07:16:08 +00:00
|
|
|
if w.Code != 200 {
|
2022-01-12 21:12:40 +00:00
|
|
|
t.Errorf("server not initially claimable")
|
2022-01-12 07:16:08 +00:00
|
|
|
}
|
2022-01-12 21:12:40 +00:00
|
|
|
}
|
2022-01-12 07:16:08 +00:00
|
|
|
|
2022-01-12 21:12:40 +00:00
|
|
|
func Config(t *testing.T) {
|
|
|
|
config := app.NodeConfig{Domain: "example.com", PublicLimit: 1024, AccountStorage: 4096}
|
|
|
|
auth := base64.StdEncoding.EncodeToString([]byte("admin:pass"))
|
|
|
|
body,_ := json.Marshal(config)
|
|
|
|
r := httptest.NewRequest("PUT", "/admin/config", strings.NewReader(string(body)))
|
|
|
|
r.Header.Add("Authorization","Basic " + auth)
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
app.SetNodeConfig(w, r);
|
|
|
|
if w.Code != 200 {
|
|
|
|
t.Errorf("failed to set node config")
|
|
|
|
}
|
2022-01-12 07:16:08 +00:00
|
|
|
}
|