diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bcfa03a..42f4efca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Modified node version from 10.x to 12.18.2 - Modified Notifier's struct values to be NullString and NullInt to allow empty values - Added Search ability to Logs in UI +- Fixed issue with Incidents and Checkins not being deleted once service is deleted # 0.90.60 (07-15-2020) - Added LETSENCRYPT_ENABLE (boolean) env to enable/disable letsencrypt SSL diff --git a/notifiers/command_test.go b/notifiers/command_test.go index a6e7de6a..0da6687c 100644 --- a/notifiers/command_test.go +++ b/notifiers/command_test.go @@ -15,6 +15,7 @@ import ( ) func TestCommandNotifier(t *testing.T) { + t.Parallel() t.SkipNow() err := utils.InitLogs() require.Nil(t, err) diff --git a/notifiers/discord_test.go b/notifiers/discord_test.go index 9ddb87dc..a4171416 100644 --- a/notifiers/discord_test.go +++ b/notifiers/discord_test.go @@ -19,6 +19,7 @@ var ( ) func TestDiscordNotifier(t *testing.T) { + t.Parallel() err := utils.InitLogs() require.Nil(t, err) DISCORD_URL = utils.Params.GetString("DISCORD_URL") diff --git a/notifiers/email_test.go b/notifiers/email_test.go index 0ef72543..d873335a 100644 --- a/notifiers/email_test.go +++ b/notifiers/email_test.go @@ -24,6 +24,7 @@ var ( ) func TestEmailNotifier(t *testing.T) { + t.Parallel() err := utils.InitLogs() require.Nil(t, err) diff --git a/notifiers/gotify_test.go b/notifiers/gotify_test.go index eefd1c3a..5b12c7bd 100644 --- a/notifiers/gotify_test.go +++ b/notifiers/gotify_test.go @@ -21,6 +21,7 @@ var ( ) func TestGotifyNotifier(t *testing.T) { + t.Parallel() err := utils.InitLogs() require.Nil(t, err) GOTIFY_URL = utils.Params.GetString("GOTIFY_URL") diff --git a/notifiers/mobile_test.go b/notifiers/mobile_test.go index 621c8c8c..9160e0e7 100644 --- a/notifiers/mobile_test.go +++ b/notifiers/mobile_test.go @@ -19,6 +19,7 @@ var ( ) func TestMobileNotifier(t *testing.T) { + t.Parallel() t.SkipNow() err := utils.InitLogs() require.Nil(t, err) diff --git a/notifiers/notifiers_test.go b/notifiers/notifiers_test.go index 248f4245..0c93175c 100644 --- a/notifiers/notifiers_test.go +++ b/notifiers/notifiers_test.go @@ -8,6 +8,7 @@ import ( ) func TestReplaceTemplate(t *testing.T) { + t.Parallel() temp := `{"id":{{.Service.Id}},"name":"{{.Service.Name}}"}` replaced := ReplaceTemplate(temp, replacer{Service: services.Example(true)}) assert.Equal(t, `{"id":6283,"name":"Statping Example"}`, replaced) diff --git a/notifiers/pushover_test.go b/notifiers/pushover_test.go index 7e0b4c2c..d885408b 100644 --- a/notifiers/pushover_test.go +++ b/notifiers/pushover_test.go @@ -19,6 +19,7 @@ var ( ) func TestPushoverNotifier(t *testing.T) { + t.Parallel() err := utils.InitLogs() require.Nil(t, err) diff --git a/notifiers/slack_test.go b/notifiers/slack_test.go index dd02a851..508305ed 100644 --- a/notifiers/slack_test.go +++ b/notifiers/slack_test.go @@ -19,6 +19,7 @@ var ( ) func TestSlackNotifier(t *testing.T) { + t.Parallel() err := utils.InitLogs() require.Nil(t, err) db, err := database.OpenTester() diff --git a/notifiers/statping_emailer_test.go b/notifiers/statping_emailer_test.go index 953b6301..103bafca 100644 --- a/notifiers/statping_emailer_test.go +++ b/notifiers/statping_emailer_test.go @@ -19,6 +19,7 @@ var ( ) func TestStatpingEmailerNotifier(t *testing.T) { + t.Parallel() err := utils.InitLogs() require.Nil(t, err) db, err := database.OpenTester() diff --git a/notifiers/telegram_test.go b/notifiers/telegram_test.go index 83579407..022c3b0d 100644 --- a/notifiers/telegram_test.go +++ b/notifiers/telegram_test.go @@ -20,6 +20,10 @@ var ( ) func TestTelegramNotifier(t *testing.T) { + t.Parallel() + + telegramToken = utils.Params.GetString("TELEGRAM_TOKEN") + telegramChannel = utils.Params.GetString("TELEGRAM_CHANNEL") if telegramToken == "" || telegramChannel == "" { t.Log("Telegram notifier testing skipped, missing TELEGRAM_TOKEN and TELEGRAM_CHANNEL environment variable") t.SkipNow() @@ -28,8 +32,6 @@ func TestTelegramNotifier(t *testing.T) { err := utils.InitLogs() require.Nil(t, err) - telegramToken = utils.Params.GetString("TELEGRAM_TOKEN") - telegramChannel = utils.Params.GetString("TELEGRAM_CHANNEL") Telegram.ApiSecret = null.NewNullString(telegramToken) Telegram.Var1 = null.NewNullString(telegramChannel) diff --git a/notifiers/twilio_test.go b/notifiers/twilio_test.go index 7cca496f..7e2a2ef8 100644 --- a/notifiers/twilio_test.go +++ b/notifiers/twilio_test.go @@ -20,6 +20,8 @@ var ( ) func TestTwilioNotifier(t *testing.T) { + t.Parallel() + err := utils.InitLogs() require.Nil(t, err) diff --git a/notifiers/webhook_test.go b/notifiers/webhook_test.go index ca1c4483..25fbbcff 100644 --- a/notifiers/webhook_test.go +++ b/notifiers/webhook_test.go @@ -21,6 +21,7 @@ var ( ) func TestWebhookNotifier(t *testing.T) { + t.Parallel() t.SkipNow() err := utils.InitLogs() require.Nil(t, err) diff --git a/types/incidents/database.go b/types/incidents/database.go index f3774efc..2c8941b5 100644 --- a/types/incidents/database.go +++ b/types/incidents/database.go @@ -87,5 +87,10 @@ func (i *Incident) Update() error { } func (i *Incident) Delete() error { + for _, u := range i.Updates() { + if err := u.Delete(); err != nil { + return err + } + } return db.Delete(i).Error() } diff --git a/types/services/database.go b/types/services/database.go index d52d7290..0992fc7e 100644 --- a/types/services/database.go +++ b/types/services/database.go @@ -102,6 +102,9 @@ func (s *Service) Delete() error { if err := s.DeleteCheckins(); err != nil { return err } + if err := s.DeleteIncidents(); err != nil { + return err + } delete(allServices, s.Id) q := db.Model(&Service{}).Delete(s) return q.Error() diff --git a/types/services/incidents.go b/types/services/incidents.go new file mode 100644 index 00000000..8e7349c6 --- /dev/null +++ b/types/services/incidents.go @@ -0,0 +1,20 @@ +package services + +import ( + "github.com/statping/statping/types/incidents" +) + +func (s *Service) Incidents() []*incidents.Incident { + var i []*incidents.Incident + db.Where("service = ?", s.Id).Find(&i) + return i +} + +func (s *Service) DeleteIncidents() error { + for _, i := range s.Incidents() { + if err := i.Delete(); err != nil { + return err + } + } + return nil +} diff --git a/types/services/services_test.go b/types/services/services_test.go index 71b17681..07fadf1f 100644 --- a/types/services/services_test.go +++ b/types/services/services_test.go @@ -9,6 +9,7 @@ import ( "github.com/statping/statping/types/checkins" "github.com/statping/statping/types/failures" "github.com/statping/statping/types/hits" + "github.com/statping/statping/types/incidents" "github.com/statping/statping/types/null" "github.com/statping/statping/utils" "github.com/stretchr/testify/assert" @@ -83,6 +84,20 @@ var fail2 = &failures.Failure{ CreatedAt: utils.Now().Add(-5 * time.Second), } +var incident1 = &incidents.Incident{ + Title: "Theres something going on", + Description: "this is an example", + ServiceId: 1, + CreatedAt: utils.Now().Add(-30 * time.Second), +} + +var incidentUpdate1 = &incidents.IncidentUpdate{ + IncidentId: 1, + Message: "This is an update", + Type: "pending", + CreatedAt: utils.Now().Add(-5 * time.Second), +} + type exampleGRPC struct { pb.UnimplementedRouteGuideServer } @@ -168,9 +183,10 @@ func TestServices(t *testing.T) { require.Nil(t, err) db, err := database.OpenTester() require.Nil(t, err) - db.AutoMigrate(&Service{}, &hits.Hit{}, &checkins.Checkin{}, &checkins.CheckinHit{}, &failures.Failure{}) + db.AutoMigrate(&Service{}, &hits.Hit{}, &checkins.Checkin{}, &checkins.CheckinHit{}, &failures.Failure{}, &incidents.Incident{}, &incidents.IncidentUpdate{}) checkins.SetDB(db) failures.SetDB(db) + incidents.SetDB(db) hits.SetDB(db) SetDB(db) @@ -181,6 +197,8 @@ func TestServices(t *testing.T) { db.Create(&exmapleCheckin) db.Create(&fail1) db.Create(&fail2) + db.Create(&incident1) + db.Create(&incidentUpdate1) tlsCert := utils.Params.GetString("STATPING_DIR") + "/cert.pem" tlsCertKey := utils.Params.GetString("STATPING_DIR") + "/key.pem" @@ -499,6 +517,22 @@ func TestServices(t *testing.T) { err = item.Delete() require.Nil(t, err) + checkin := item.Checkins() + assert.Len(t, checkin, 0) + for _, c := range checkin { + assert.Len(t, c.Failures().List(), 0) + assert.Len(t, c.Hits(), 0) + } + + assert.Len(t, item.AllFailures().List(), 0) + assert.Len(t, item.AllHits().List(), 0) + + inc := item.Incidents() + assert.Len(t, inc, 0) + for _, i := range inc { + assert.Len(t, i.Updates(), 0) + } + all = All() assert.Len(t, all, 1) })