From 000d98d9345c9e9e424293252114feffb73b9181 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Tue, 11 Jan 2022 23:16:08 -0800 Subject: [PATCH] adding tests --- net/server/main_test.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/net/server/main_test.go b/net/server/main_test.go index b37f99a8..6933f401 100644 --- a/net/server/main_test.go +++ b/net/server/main_test.go @@ -1,16 +1,22 @@ package main import ( + "fmt" "testing" "net/http/httptest" + "encoding/base64" app "databag/internal" store "databag/internal/store" ) -func TestClaim(t *testing.T) { +func TestSetup(t *testing.T) { store.SetPath("file::memory:?cache=shared"); + Claimable(t); + Claim(t); +} +func Claimable(t *testing.T) { r := httptest.NewRequest("GET", "/claimable", nil) w := httptest.NewRecorder() 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"); + } + +}