Big refactor to allow for multiple watchers, v2 configuration file with migration and new UI for configuration
This commit is contained in:
@@ -6,15 +6,19 @@ import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/tardisx/discord-auto-upload/config"
|
||||
)
|
||||
|
||||
func TestHome(t *testing.T) {
|
||||
s := WebService{}
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
w := httptest.NewRecorder()
|
||||
getStatic(w, req)
|
||||
s.getStatic(w, req)
|
||||
res := w.Result()
|
||||
defer res.Body.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("expected error to be nil got %v", err)
|
||||
}
|
||||
@@ -28,6 +32,7 @@ func TestHome(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNotFound(t *testing.T) {
|
||||
s := WebService{}
|
||||
|
||||
notFounds := []string{
|
||||
"/abc.html", "/foo.html", "/foo.html", "/../foo.html",
|
||||
@@ -38,8 +43,9 @@ func TestNotFound(t *testing.T) {
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, nf, nil)
|
||||
w := httptest.NewRecorder()
|
||||
getStatic(w, req)
|
||||
s.getStatic(w, req)
|
||||
res := w.Result()
|
||||
|
||||
defer res.Body.Close()
|
||||
b, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
@@ -54,3 +60,25 @@ func TestNotFound(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetConfig(t *testing.T) {
|
||||
conf := config.DefaultConfigService()
|
||||
conf.Config = *config.DefaultConfig()
|
||||
s := WebService{Config: *conf}
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/rest/config", nil)
|
||||
w := httptest.NewRecorder()
|
||||
s.handleConfig(w, req)
|
||||
res := w.Result()
|
||||
defer res.Body.Close()
|
||||
|
||||
b, err := ioutil.ReadAll(res.Body)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("expected error to be nil got %v", err)
|
||||
}
|
||||
|
||||
if string(b) != `{"WatchInterval":10,"Version":2,"Watchers":[{"WebHookURL":"abcedf","Path":"/Users/justin/tmp","Username":"","NoWatermark":false,"Exclude":[]}]}` {
|
||||
t.Errorf("Got unexpected response %v", string(b))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user