mirror of https://github.com/statping/statping
additional testing
parent
0a55ae08c9
commit
2aa86b28d6
|
@ -65,6 +65,10 @@ func RunInit(db string, t *testing.T) {
|
||||||
core.CoreApp = core.NewCore()
|
core.CoreApp = core.NewCore()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
m.Run()
|
||||||
|
}
|
||||||
|
|
||||||
func TestRunAll(t *testing.T) {
|
func TestRunAll(t *testing.T) {
|
||||||
//t.Parallel()
|
//t.Parallel()
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,14 @@ func InsertSampleData() error {
|
||||||
s4.Create(false)
|
s4.Create(false)
|
||||||
s5.Create(false)
|
s5.Create(false)
|
||||||
|
|
||||||
|
utils.Log(1, "Sample data has finished importing")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// insertSampleCheckins will create 2 checkins with 60 successful hits per checkin
|
||||||
|
func insertSampleCheckins() error {
|
||||||
|
s1 := SelectService(1)
|
||||||
checkin1 := ReturnCheckin(&types.Checkin{
|
checkin1 := ReturnCheckin(&types.Checkin{
|
||||||
Service: s1.Id,
|
Service: s1.Id,
|
||||||
Interval: 300,
|
Interval: 300,
|
||||||
|
@ -91,6 +99,7 @@ func InsertSampleData() error {
|
||||||
})
|
})
|
||||||
checkin1.Update()
|
checkin1.Update()
|
||||||
|
|
||||||
|
s2 := SelectService(1)
|
||||||
checkin2 := ReturnCheckin(&types.Checkin{
|
checkin2 := ReturnCheckin(&types.Checkin{
|
||||||
Service: s2.Id,
|
Service: s2.Id,
|
||||||
Interval: 900,
|
Interval: 900,
|
||||||
|
@ -108,9 +117,6 @@ func InsertSampleData() error {
|
||||||
checkHit.Create()
|
checkHit.Create()
|
||||||
checkTime = checkTime.Add(10 * time.Minute)
|
checkTime = checkTime.Add(10 * time.Minute)
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.Log(1, "Sample data has finished importing")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,6 +186,7 @@ func InsertLargeSampleData() error {
|
||||||
insertSampleCore()
|
insertSampleCore()
|
||||||
InsertSampleData()
|
InsertSampleData()
|
||||||
insertSampleUsers()
|
insertSampleUsers()
|
||||||
|
insertSampleCheckins()
|
||||||
s6 := ReturnService(&types.Service{
|
s6 := ReturnService(&types.Service{
|
||||||
Name: "JSON Lint",
|
Name: "JSON Lint",
|
||||||
Domain: "https://jsonlint.com",
|
Domain: "https://jsonlint.com",
|
||||||
|
|
|
@ -245,6 +245,31 @@ func TestApiServiceDataHandler(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestApiRenewHandler(t *testing.T) {
|
||||||
|
api := core.CoreApp.ApiKey
|
||||||
|
secret := core.CoreApp.ApiSecret
|
||||||
|
rr, err := httpRequestAPI(t, "GET", "/api/renew", nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
body := rr.Body.String()
|
||||||
|
var obj apiResponse
|
||||||
|
formatJSON(body, &obj)
|
||||||
|
assert.Equal(t, 303, rr.Code)
|
||||||
|
assert.NotEqual(t, api, core.CoreApp.ApiKey)
|
||||||
|
assert.NotEqual(t, secret, core.CoreApp.ApiSecret)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApiCheckinHandler(t *testing.T) {
|
||||||
|
t.SkipNow()
|
||||||
|
service := core.SelectService(1)
|
||||||
|
checkin := service.Checkins()
|
||||||
|
rr, err := httpRequestAPI(t, "GET", "/api/checkin/"+checkin[0].ApiKey, nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
body := rr.Body.String()
|
||||||
|
var obj apiResponse
|
||||||
|
formatJSON(body, &obj)
|
||||||
|
assert.Equal(t, 200, rr.Code)
|
||||||
|
}
|
||||||
|
|
||||||
func httpRequestAPI(t *testing.T, method, url string, body io.Reader) (*httptest.ResponseRecorder, error) {
|
func httpRequestAPI(t *testing.T, method, url string, body io.Reader) (*httptest.ResponseRecorder, error) {
|
||||||
req, err := http.NewRequest(method, url, body)
|
req, err := http.NewRequest(method, url, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -244,7 +244,7 @@ func TestUsersEditHandler(t *testing.T) {
|
||||||
body := rr.Body.String()
|
body := rr.Body.String()
|
||||||
assert.Equal(t, 200, rr.Code)
|
assert.Equal(t, 200, rr.Code)
|
||||||
assert.Contains(t, body, "<title>Statup | admin</title>")
|
assert.Contains(t, body, "<title>Statup | admin</title>")
|
||||||
assert.Contains(t, body, "<h3>user admin</h3>")
|
assert.Contains(t, body, "<h3>User admin</h3>")
|
||||||
assert.Contains(t, body, "value=\"info@statup.io\"")
|
assert.Contains(t, body, "value=\"info@statup.io\"")
|
||||||
assert.Contains(t, body, "value=\"##########\"")
|
assert.Contains(t, body, "value=\"##########\"")
|
||||||
assert.Contains(t, body, "Statup made with ❤️")
|
assert.Contains(t, body, "Statup made with ❤️")
|
||||||
|
@ -613,6 +613,15 @@ func TestReorderServiceHandler(t *testing.T) {
|
||||||
assert.True(t, isRouteAuthenticated(req))
|
assert.True(t, isRouteAuthenticated(req))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExportHandler(t *testing.T) {
|
||||||
|
req, err := http.NewRequest("GET", "/settings/export", nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
Router().ServeHTTP(rr, req)
|
||||||
|
assert.Equal(t, 200, rr.Code)
|
||||||
|
assert.True(t, isRouteAuthenticated(req))
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateBulkServices(t *testing.T) {
|
func TestCreateBulkServices(t *testing.T) {
|
||||||
domains := []string{
|
domains := []string{
|
||||||
"https://status.coinapp.io",
|
"https://status.coinapp.io",
|
||||||
|
|
|
@ -22,45 +22,12 @@ import (
|
||||||
"github.com/hunterlong/statup/core"
|
"github.com/hunterlong/statup/core"
|
||||||
"github.com/hunterlong/statup/types"
|
"github.com/hunterlong/statup/types"
|
||||||
"github.com/hunterlong/statup/utils"
|
"github.com/hunterlong/statup/utils"
|
||||||
"github.com/jinzhu/now"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func renderServiceChartHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
vars := mux.Vars(r)
|
|
||||||
fields := parseGet(r)
|
|
||||||
w.Header().Set("Content-Type", "text/javascript")
|
|
||||||
w.Header().Set("Cache-Control", "max-age=30")
|
|
||||||
|
|
||||||
startField := fields.Get("start")
|
|
||||||
endField := fields.Get("end")
|
|
||||||
|
|
||||||
end := now.EndOfDay().UTC()
|
|
||||||
start := now.BeginningOfDay().UTC()
|
|
||||||
|
|
||||||
if startField != "" {
|
|
||||||
start = time.Unix(utils.StringInt(startField), 0)
|
|
||||||
start = now.New(start).BeginningOfDay().UTC()
|
|
||||||
}
|
|
||||||
if endField != "" {
|
|
||||||
end = time.Unix(utils.StringInt(endField), 0)
|
|
||||||
end = now.New(end).EndOfDay().UTC()
|
|
||||||
}
|
|
||||||
|
|
||||||
service := core.SelectService(utils.StringInt(vars["id"]))
|
|
||||||
data := core.GraphDataRaw(service, start, end, "hour", "latency").ToString()
|
|
||||||
|
|
||||||
out := struct {
|
|
||||||
Services []*core.Service
|
|
||||||
Data []string
|
|
||||||
}{[]*core.Service{service}, []string{data}}
|
|
||||||
|
|
||||||
executeResponse(w, r, "charts.js", out, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func renderServiceChartsHandler(w http.ResponseWriter, r *http.Request) {
|
func renderServiceChartsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
services := core.CoreApp.Services
|
services := core.CoreApp.Services
|
||||||
w.Header().Set("Content-Type", "text/javascript")
|
w.Header().Set("Content-Type", "text/javascript")
|
||||||
|
|
|
@ -92,6 +92,11 @@ func TestDiscordNotifier(t *testing.T) {
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("discord Test", func(t *testing.T) {
|
||||||
|
err := discorder.OnTest()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("discord Queue", func(t *testing.T) {
|
t.Run("discord Queue", func(t *testing.T) {
|
||||||
go notifier.Queue(discorder)
|
go notifier.Queue(discorder)
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
|
@ -128,6 +128,11 @@ func TestEmailNotifier(t *testing.T) {
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("emailer Test", func(t *testing.T) {
|
||||||
|
err := emailer.OnTest()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("email Run Queue", func(t *testing.T) {
|
t.Run("email Run Queue", func(t *testing.T) {
|
||||||
go notifier.Queue(emailer)
|
go notifier.Queue(emailer)
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
|
|
@ -101,6 +101,11 @@ func TestSlackNotifier(t *testing.T) {
|
||||||
assert.Len(t, slacker.Queue, 3)
|
assert.Len(t, slacker.Queue, 3)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("slack Test", func(t *testing.T) {
|
||||||
|
err := slacker.OnTest()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("slack Queue", func(t *testing.T) {
|
t.Run("slack Queue", func(t *testing.T) {
|
||||||
go notifier.Queue(slacker)
|
go notifier.Queue(slacker)
|
||||||
time.Sleep(4 * time.Second)
|
time.Sleep(4 * time.Second)
|
||||||
|
|
|
@ -99,6 +99,11 @@ func TestTwilioNotifier(t *testing.T) {
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Twilio Test", func(t *testing.T) {
|
||||||
|
err := twilioNotifier.OnTest()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Twilio Queue", func(t *testing.T) {
|
t.Run("Twilio Queue", func(t *testing.T) {
|
||||||
go notifier.Queue(twilioNotifier)
|
go notifier.Queue(twilioNotifier)
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
Loading…
Reference in New Issue