Rename TestStore_Insert to TestStore_SanityCheck

This commit is contained in:
TwinProduction 2021-07-18 23:13:19 -04:00
parent cf48072167
commit 46cf616a57
2 changed files with 17 additions and 11 deletions

View File

@ -80,9 +80,9 @@ var (
} }
) )
// Note that there is a much more extensive test in /storage/store/store_test.go. // Note that are much more extensive tests in /storage/store/store_test.go.
// This test is simply an extra sanity check // This test is simply an extra sanity check
func TestStore_Insert(t *testing.T) { func TestStore_SanityCheck(t *testing.T) {
store, _ := NewStore("") store, _ := NewStore("")
store.Insert(&testService, &testSuccessfulResult) store.Insert(&testService, &testSuccessfulResult)
if numberOfServiceStatuses := len(store.GetAllServiceStatuses(paging.NewServiceStatusParams())); numberOfServiceStatuses != 1 { if numberOfServiceStatuses := len(store.GetAllServiceStatuses(paging.NewServiceStatusParams())); numberOfServiceStatuses != 1 {
@ -93,15 +93,18 @@ func TestStore_Insert(t *testing.T) {
if numberOfServiceStatuses := len(store.GetAllServiceStatuses(paging.NewServiceStatusParams())); numberOfServiceStatuses != 1 { if numberOfServiceStatuses := len(store.GetAllServiceStatuses(paging.NewServiceStatusParams())); numberOfServiceStatuses != 1 {
t.Fatalf("expected 1 ServiceStatus, got %d", numberOfServiceStatuses) t.Fatalf("expected 1 ServiceStatus, got %d", numberOfServiceStatuses)
} }
ss := store.GetServiceStatusByKey(testService.Key(), paging.NewServiceStatusParams().WithResults(1, 20).WithEvents(1, 20)) ss := store.GetServiceStatus(testService.Group, testService.Name, paging.NewServiceStatusParams().WithResults(1, 20).WithEvents(1, 20))
if ss == nil { if ss == nil {
t.Fatalf("Store should've had key '%s', but didn't", testService.Key()) t.Fatalf("Store should've had key '%s', but didn't", testService.Key())
} }
if len(ss.Events) != 3 { if len(ss.Events) != 3 {
t.Fatalf("Service '%s' should've had 3 events, got %d", ss.Name, len(ss.Events)) t.Errorf("Service '%s' should've had 3 events, got %d", ss.Name, len(ss.Events))
} }
if len(ss.Results) != 2 { if len(ss.Results) != 2 {
t.Fatalf("Service '%s' should've had 2 results, got %d", ss.Name, len(ss.Results)) t.Errorf("Service '%s' should've had 2 results, got %d", ss.Name, len(ss.Results))
}
if deleted := store.DeleteAllServiceStatusesNotInKeys([]string{}); deleted != 1 {
t.Errorf("%d entries should've been deleted, got %d", 1, deleted)
} }
} }

View File

@ -250,10 +250,10 @@ func TestStore_Save(t *testing.T) {
} }
} }
// Note that there is a much more extensive test in /storage/store/store_test.go. // Note that are much more extensive tests in /storage/store/store_test.go.
// This test is simply an extra sanity check // This test is simply an extra sanity check
func TestStore_Insert(t *testing.T) { func TestStore_SanityCheck(t *testing.T) {
store, _ := NewStore("sqlite", t.TempDir()+"/TestStore_Insert.db") store, _ := NewStore("sqlite", t.TempDir()+"/TestStore_SanityCheck.db")
defer store.Close() defer store.Close()
store.Insert(&testService, &testSuccessfulResult) store.Insert(&testService, &testSuccessfulResult)
if numberOfServiceStatuses := len(store.GetAllServiceStatuses(paging.NewServiceStatusParams())); numberOfServiceStatuses != 1 { if numberOfServiceStatuses := len(store.GetAllServiceStatuses(paging.NewServiceStatusParams())); numberOfServiceStatuses != 1 {
@ -264,15 +264,18 @@ func TestStore_Insert(t *testing.T) {
if numberOfServiceStatuses := len(store.GetAllServiceStatuses(paging.NewServiceStatusParams())); numberOfServiceStatuses != 1 { if numberOfServiceStatuses := len(store.GetAllServiceStatuses(paging.NewServiceStatusParams())); numberOfServiceStatuses != 1 {
t.Fatalf("expected 1 ServiceStatus, got %d", numberOfServiceStatuses) t.Fatalf("expected 1 ServiceStatus, got %d", numberOfServiceStatuses)
} }
ss := store.GetServiceStatusByKey(testService.Key(), paging.NewServiceStatusParams().WithResults(1, 20).WithEvents(1, 20)) ss := store.GetServiceStatus(testService.Group, testService.Name, paging.NewServiceStatusParams().WithResults(1, 20).WithEvents(1, 20))
if ss == nil { if ss == nil {
t.Fatalf("Store should've had key '%s', but didn't", testService.Key()) t.Fatalf("Store should've had key '%s', but didn't", testService.Key())
} }
if len(ss.Events) != 3 { if len(ss.Events) != 3 {
t.Fatalf("Service '%s' should've had 3 events, got %d", ss.Name, len(ss.Events)) t.Errorf("Service '%s' should've had 3 events, got %d", ss.Name, len(ss.Events))
} }
if len(ss.Results) != 2 { if len(ss.Results) != 2 {
t.Fatalf("Service '%s' should've had 2 results, got %d", ss.Name, len(ss.Results)) t.Errorf("Service '%s' should've had 2 results, got %d", ss.Name, len(ss.Results))
}
if deleted := store.DeleteAllServiceStatusesNotInKeys([]string{}); deleted != 1 {
t.Errorf("%d entries should've been deleted, got %d", 1, deleted)
} }
} }