adding tests

This commit is contained in:
Roland Osborne 2022-01-11 23:16:08 -08:00
parent 0b1315f9bf
commit 000d98d934

View File

@ -1,16 +1,22 @@
package main package main
import ( import (
"fmt"
"testing" "testing"
"net/http/httptest" "net/http/httptest"
"encoding/base64"
app "databag/internal" app "databag/internal"
store "databag/internal/store" store "databag/internal/store"
) )
func TestClaim(t *testing.T) { func TestSetup(t *testing.T) {
store.SetPath("file::memory:?cache=shared"); store.SetPath("file::memory:?cache=shared");
Claimable(t);
Claim(t);
}
func Claimable(t *testing.T) {
r := httptest.NewRequest("GET", "/claimable", nil) r := httptest.NewRequest("GET", "/claimable", nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()
app.GetNodeClaimable(w, r); app.GetNodeClaimable(w, r);
@ -19,3 +25,14 @@ func TestClaim(t *testing.T) {
} }
} }
func Claim(t *testing.T) {
auth := base64.StdEncoding.EncodeToString([]byte("admin:pass"))
r := httptest.NewRequest("GET", "/claimable", nil)
r.Header.Add("Authorization","Basic " + auth)
w := httptest.NewRecorder()
app.GetNodeClaimable(w, r);
if w.Code != 200 {
t.Errorf("server not initially claimable");
}
}