mirror of https://github.com/statping/statping
gorm changes - tests
parent
5128b153a9
commit
82ac8bfc27
|
@ -30,7 +30,6 @@ type Failure struct {
|
|||
|
||||
// CreateFailure will create a new failure record for a service
|
||||
func (s *Service) CreateFailure(f *types.Failure) (int64, error) {
|
||||
f.CreatedAt = time.Now().UTC()
|
||||
f.Service = s.Id
|
||||
s.Failures = append(s.Failures, f)
|
||||
row := failuresDB().Create(f)
|
||||
|
|
|
@ -27,7 +27,6 @@ type Hit struct {
|
|||
|
||||
// CreateHit will create a new 'hit' record in the database for a successful/online service
|
||||
func (s *Service) CreateHit(h *types.Hit) (int64, error) {
|
||||
h.CreatedAt = time.Now().UTC()
|
||||
db := hitsDB().Create(h)
|
||||
if db.Error != nil {
|
||||
utils.Log(2, db.Error)
|
||||
|
|
|
@ -232,7 +232,7 @@ func TestRunAllQueueAndStop(t *testing.T) {
|
|||
assert.Equal(t, 16, len(example.Queue))
|
||||
go Queue(example)
|
||||
assert.Equal(t, 16, len(example.Queue))
|
||||
time.Sleep(15 * time.Second)
|
||||
time.Sleep(13 * time.Second)
|
||||
assert.Equal(t, 6, len(example.Queue))
|
||||
time.Sleep(1 * time.Second)
|
||||
assert.Equal(t, 6, len(example.Queue))
|
||||
|
|
|
@ -166,6 +166,56 @@ 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()
|
||||
if len(fails) == 0 {
|
||||
return time.Duration(0)
|
||||
}
|
||||
since := fails[0].CreatedAt.Sub(hits[0].CreatedAt)
|
||||
return since
|
||||
}
|
||||
|
||||
func (s *Service) GraphDataRaw() []*DateScan {
|
||||
var d []*DateScan
|
||||
since := time.Now().Add(time.Hour*-24 + time.Minute*0 + time.Second*0)
|
||||
|
|
|
@ -45,6 +45,12 @@ func TestSelectAllServices(t *testing.T) {
|
|||
assert.Equal(t, 15, len(services))
|
||||
}
|
||||
|
||||
func TestServiceDowntime(t *testing.T) {
|
||||
service := SelectService(15)
|
||||
downtime := service.Downtime()
|
||||
assert.True(t, downtime.Minutes() > 9)
|
||||
}
|
||||
|
||||
func TestSelectTCPService(t *testing.T) {
|
||||
services := CoreApp.Services
|
||||
assert.Equal(t, 15, len(services))
|
||||
|
|
Loading…
Reference in New Issue