Use a fixed date instead

This commit is contained in:
TwinProduction 2021-01-08 23:40:43 -05:00
parent eaf205eded
commit 907b611505

View File

@ -13,7 +13,7 @@ var (
secondCondition = core.Condition("[RESPONSE_TIME] < 500") secondCondition = core.Condition("[RESPONSE_TIME] < 500")
thirdCondition = core.Condition("[CERTIFICATE_EXPIRATION] < 72h") thirdCondition = core.Condition("[CERTIFICATE_EXPIRATION] < 72h")
timestamp = time.Date(2020, 4, 29, 12, 45, 0, 0, time.UTC) timestamp, _ = time.ParseInLocation(time.RFC3339, "2021-01-08T23:39:37-05:00", time.Local)
testService = core.Service{ testService = core.Service{
Name: "name", Name: "name",
@ -139,14 +139,28 @@ func TestInMemoryStore_Insert(t *testing.T) {
} }
} }
func TestInMemoryStore_GetServiceStatusForExistingStatusReturnsThatServiceStatus(t *testing.T) { func TestInMemoryStore_GetServiceStatus(t *testing.T) {
store := NewInMemoryStore() store := NewInMemoryStore()
store.Insert(&testService, &testSuccessfulResult) store.Insert(&testService, &testSuccessfulResult)
store.Insert(&testService, &testUnsuccessfulResult)
serviceStatus := store.GetServiceStatus(testService.Group, testService.Name) serviceStatus := store.GetServiceStatus(testService.Group, testService.Name)
if serviceStatus == nil { if serviceStatus == nil {
t.Errorf("Returned service status for group '%s' and name '%s' was nil after inserting the service into the store", testService.Group, testService.Name) t.Fatalf("serviceStatus shouldn't have been nil")
} }
if serviceStatus.Uptime == nil {
t.Fatalf("serviceStatus.Uptime shouldn't have been nil")
}
if serviceStatus.Uptime.LastHour != 0.5 {
t.Errorf("serviceStatus.Uptime.LastHour should've been 0.5")
}
if serviceStatus.Uptime.LastTwentyFourHours != 0.5 {
t.Errorf("serviceStatus.Uptime.LastTwentyFourHours should've been 0.5")
}
if serviceStatus.Uptime.LastSevenDays != 0.5 {
t.Errorf("serviceStatus.Uptime.LastSevenDays should've been 0.5")
}
fmt.Println(serviceStatus.Results[0].Timestamp.Format(time.RFC3339))
} }
func TestInMemoryStore_GetServiceStatusForMissingStatusReturnsNil(t *testing.T) { func TestInMemoryStore_GetServiceStatusForMissingStatusReturnsNil(t *testing.T) {
@ -175,7 +189,7 @@ func TestInMemoryStore_GetAllAsJSON(t *testing.T) {
if err != nil { if err != nil {
t.Fatal("shouldn't have returned an error, got", err.Error()) t.Fatal("shouldn't have returned an error, got", err.Error())
} }
expectedOutput := `{"group_name":{"name":"name","group":"group","results":[{"status":200,"hostname":"example.org","duration":150000000,"errors":null,"condition-results":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":true},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":true}],"success":true,"timestamp":"2020-04-29T12:45:00Z"},{"status":200,"hostname":"example.org","duration":750000000,"errors":["error-1","error-2"],"condition-results":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":false},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":false}],"success":false,"timestamp":"2020-04-29T12:45:00Z"}],"uptime":{"7d":0.5,"24h":0.5,"1h":0.5}}}` expectedOutput := `{"group_name":{"name":"name","group":"group","results":[{"status":200,"hostname":"example.org","duration":150000000,"errors":null,"condition-results":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":true},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":true}],"success":true,"timestamp":"2021-01-08T23:39:37-05:00"},{"status":200,"hostname":"example.org","duration":750000000,"errors":["error-1","error-2"],"condition-results":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":false},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":false}],"success":false,"timestamp":"2021-01-08T23:39:37-05:00"}],"uptime":{"7d":0.5,"24h":0.5,"1h":0.5}}}`
if string(output) != expectedOutput { if string(output) != expectedOutput {
t.Error(string(output)) t.Error(string(output))
} }