mirror of https://github.com/statping/statping
timestamp - tests
parent
673852b3c9
commit
baa4ac49ce
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
|||
VERSION=0.61
|
||||
VERSION=0.63
|
||||
BINARY_NAME=statup
|
||||
GOPATH:=$(GOPATH)
|
||||
GOCMD=go
|
||||
|
|
|
@ -83,6 +83,46 @@ func (db *DbConfig) Close() error {
|
|||
return DbSession.DB().Close()
|
||||
}
|
||||
|
||||
func (s *Service) AfterFind() (err error) {
|
||||
s.CreatedAt = utils.Timezoner(s.CreatedAt, CoreApp.Timezone)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Hit) AfterFind() (err error) {
|
||||
s.CreatedAt = utils.Timezoner(s.CreatedAt, CoreApp.Timezone)
|
||||
return
|
||||
}
|
||||
|
||||
func (f *Failure) AfterFind() (err error) {
|
||||
f.CreatedAt = utils.Timezoner(f.CreatedAt, CoreApp.Timezone)
|
||||
return
|
||||
}
|
||||
|
||||
func (u *User) AfterFind() (err error) {
|
||||
u.CreatedAt = utils.Timezoner(u.CreatedAt, CoreApp.Timezone)
|
||||
return
|
||||
}
|
||||
|
||||
func (u *Hit) BeforeCreate() (err error) {
|
||||
u.CreatedAt = time.Now().UTC()
|
||||
return
|
||||
}
|
||||
|
||||
func (u *Failure) BeforeCreate() (err error) {
|
||||
u.CreatedAt = time.Now().UTC()
|
||||
return
|
||||
}
|
||||
|
||||
func (u *User) BeforeCreate() (err error) {
|
||||
u.CreatedAt = time.Now().UTC()
|
||||
return
|
||||
}
|
||||
|
||||
func (u *Service) BeforeCreate() (err error) {
|
||||
u.CreatedAt = time.Now().UTC()
|
||||
return
|
||||
}
|
||||
|
||||
// InsertCore create the single row for the Core settings in Statup
|
||||
func (db *DbConfig) InsertCore() (*Core, error) {
|
||||
CoreApp = &Core{Core: &types.Core{
|
||||
|
|
|
@ -166,46 +166,6 @@ func GroupDataBy(column string, id int64, tm time.Time, increment string) string
|
|||
return sql
|
||||
}
|
||||
|
||||
func (s *Service) AfterFind() (err error) {
|
||||
s.CreatedAt = utils.Timezoner(s.CreatedAt, CoreApp.Timezone)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Hit) AfterFind() (err error) {
|
||||
s.CreatedAt = utils.Timezoner(s.CreatedAt, CoreApp.Timezone)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Failure) AfterFind() (err error) {
|
||||
s.CreatedAt = utils.Timezoner(s.CreatedAt, CoreApp.Timezone)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *User) AfterFind() (err error) {
|
||||
s.CreatedAt = utils.Timezoner(s.CreatedAt, CoreApp.Timezone)
|
||||
return
|
||||
}
|
||||
|
||||
func (u *Hit) BeforeCreate() (err error) {
|
||||
u.CreatedAt = time.Now().UTC()
|
||||
return
|
||||
}
|
||||
|
||||
func (u *Failure) BeforeCreate() (err error) {
|
||||
u.CreatedAt = time.Now().UTC()
|
||||
return
|
||||
}
|
||||
|
||||
func (u *User) BeforeCreate() (err error) {
|
||||
u.CreatedAt = time.Now().UTC()
|
||||
return
|
||||
}
|
||||
|
||||
func (u *Service) BeforeCreate() (err error) {
|
||||
u.CreatedAt = time.Now().UTC()
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Service) Downtime() time.Duration {
|
||||
hits, _ := s.Hits()
|
||||
fails := s.LimitedFailures()
|
||||
|
|
|
@ -47,8 +47,8 @@ func Router() *mux.Router {
|
|||
r.PathPrefix("/statup.png").Handler(http.FileServer(source.TmplBox.HTTPBox()))
|
||||
}
|
||||
r.PathPrefix("/js/").Handler(http.StripPrefix("/js/", http.FileServer(source.JsBox.HTTPBox())))
|
||||
r.Handle("/charts.js", http.HandlerFunc(renderServiceChartsHandler))
|
||||
r.Handle("/charts/{id}.js", http.HandlerFunc(renderServiceChartHandler))
|
||||
r.Handle("/charts.js", http.HandlerFunc(renderServiceChartsHandler))
|
||||
r.Handle("/setup", http.HandlerFunc(setupHandler)).Methods("GET")
|
||||
r.Handle("/setup", http.HandlerFunc(processSetupHandler)).Methods("POST")
|
||||
r.Handle("/dashboard", http.HandlerFunc(dashboardHandler)).Methods("GET")
|
||||
|
|
|
@ -14,6 +14,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
DISCORD_URL = os.Getenv("DISCORD_URL")
|
||||
discorder.Host = DISCORD_URL
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,13 @@ var (
|
|||
var testEmail *EmailOutgoing
|
||||
|
||||
func init() {
|
||||
EMAIL_HOST = os.Getenv("EMAIL_HOST")
|
||||
EMAIL_USER = os.Getenv("EMAIL_USER")
|
||||
EMAIL_PASS = os.Getenv("EMAIL_PASS")
|
||||
EMAIL_OUTGOING = os.Getenv("EMAIL_OUTGOING")
|
||||
EMAIL_SEND_TO = os.Getenv("EMAIL_SEND_TO")
|
||||
EMAIL_PORT = utils.StringInt(os.Getenv("EMAIL_PORT"))
|
||||
|
||||
emailer.Host = EMAIL_HOST
|
||||
emailer.Username = EMAIL_USER
|
||||
emailer.Password = EMAIL_PASS
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
SLACK_URL = os.Getenv("SLACK_URL")
|
||||
SLACK_URL string
|
||||
slackMessage = `{"text":"this is a test from the Slack notifier!"}`
|
||||
slackTestMessage = SlackMessage{
|
||||
Service: TestService,
|
||||
|
@ -19,6 +19,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
SLACK_URL = os.Getenv("SLACK_URL")
|
||||
slacker.Host = SLACK_URL
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,11 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
TWILIO_SID = os.Getenv("TWILIO_SID")
|
||||
TWILIO_SECRET = os.Getenv("TWILIO_SECRET")
|
||||
TWILIO_FROM = os.Getenv("TWILIO_FROM")
|
||||
TWILIO_TO = os.Getenv("TWILIO_TO")
|
||||
|
||||
twilioNotifier.ApiKey = TWILIO_SID
|
||||
twilioNotifier.ApiSecret = TWILIO_SECRET
|
||||
twilioNotifier.Var1 = TWILIO_TO
|
||||
|
@ -26,12 +31,12 @@ func init() {
|
|||
func TestTwilioNotifier(t *testing.T) {
|
||||
t.Parallel()
|
||||
if TWILIO_SID == "" || TWILIO_SECRET == "" || TWILIO_FROM == "" {
|
||||
t.Log("twilioNotifier notifier testing skipped, missing TWILIO_SID environment variable")
|
||||
t.Log("twilio notifier testing skipped, missing TWILIO_SID environment variable")
|
||||
t.SkipNow()
|
||||
}
|
||||
currentCount = CountNotifiers()
|
||||
|
||||
t.Run("Load twilioNotifier", func(t *testing.T) {
|
||||
t.Run("Load Twilio", func(t *testing.T) {
|
||||
twilioNotifier.ApiKey = TWILIO_SID
|
||||
twilioNotifier.Delay = time.Duration(100 * time.Millisecond)
|
||||
err := notifier.AddNotifier(twilioNotifier)
|
||||
|
@ -40,22 +45,22 @@ func TestTwilioNotifier(t *testing.T) {
|
|||
assert.Equal(t, TWILIO_SID, twilioNotifier.ApiKey)
|
||||
})
|
||||
|
||||
t.Run("Load twilioNotifier Notifier", func(t *testing.T) {
|
||||
t.Run("Load Twilio Notifier", func(t *testing.T) {
|
||||
notifier.Load()
|
||||
})
|
||||
|
||||
t.Run("twilioNotifier Within Limits", func(t *testing.T) {
|
||||
t.Run("Twilio Within Limits", func(t *testing.T) {
|
||||
ok, err := twilioNotifier.WithinLimits()
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, ok)
|
||||
})
|
||||
|
||||
t.Run("twilioNotifier Send", func(t *testing.T) {
|
||||
t.Run("Twilio Send", func(t *testing.T) {
|
||||
err := twilioNotifier.Send(twilioMessage)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
t.Run("twilioNotifier Queue", func(t *testing.T) {
|
||||
t.Run("Twilio Queue", func(t *testing.T) {
|
||||
go notifier.Queue(twilioNotifier)
|
||||
time.Sleep(1 * time.Second)
|
||||
assert.Equal(t, TWILIO_SID, twilioNotifier.ApiKey)
|
||||
|
|
|
@ -62,7 +62,6 @@ func ToString(s interface{}) string {
|
|||
|
||||
func Timezoner(t time.Time, zone float32) time.Time {
|
||||
zoneInt := float32(3600) * (zone + 1)
|
||||
fmt.Println(int(zoneInt))
|
||||
loc := time.FixedZone("", int(zoneInt))
|
||||
timez := t.In(loc)
|
||||
return timez
|
||||
|
|
|
@ -73,13 +73,12 @@ func TestDbTime(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTimezone(t *testing.T) {
|
||||
zone := -5
|
||||
zone := float32(-4.0)
|
||||
loc, _ := time.LoadLocation("America/Los_Angeles")
|
||||
timestamp := time.Date(2018, 1, 1, 10, 0, 0, 0, loc).UTC()
|
||||
correct := timestamp.Add(3 * time.Hour)
|
||||
timestamp := time.Date(2018, 1, 1, 10, 0, 0, 0, loc)
|
||||
timezone := Timezoner(timestamp, zone)
|
||||
assert.Equal(t, "2018-01-01 21:00:00 +0000 UTC", correct.String())
|
||||
assert.Equal(t, "2018-01-01 13:00:00 -0500 -0500", timezone.String())
|
||||
assert.Equal(t, "2018-01-01 10:00:00 -0800 PST", timestamp.String())
|
||||
assert.Equal(t, "2018-01-01 15:00:00 -0300 -0300", timezone.String())
|
||||
}
|
||||
|
||||
func TestTimestamp_Ago(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue