feat(badge): Implement UP/DOWN status badge (#291)
* Implement status badge endpoint * Update integration tests for status badge generation * Add status badge in the UI * Update static assets * Update README with status badge description * Rename constants to pascal-case * Check for success of the endpoint conditions * Rename status badge to health badge
This commit is contained in:
@ -13,7 +13,7 @@ import (
|
||||
"github.com/TwiN/gatus/v3/watchdog"
|
||||
)
|
||||
|
||||
func TestUptimeBadge(t *testing.T) {
|
||||
func TestBadge(t *testing.T) {
|
||||
defer store.Get().Clear()
|
||||
defer cache.Clear()
|
||||
cfg := &config.Config{
|
||||
@ -29,8 +29,8 @@ func TestUptimeBadge(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
watchdog.UpdateEndpointStatuses(cfg.Endpoints[0], &core.Result{Success: true, Duration: time.Millisecond, Timestamp: time.Now()})
|
||||
watchdog.UpdateEndpointStatuses(cfg.Endpoints[1], &core.Result{Success: false, Duration: time.Second, Timestamp: time.Now()})
|
||||
watchdog.UpdateEndpointStatuses(cfg.Endpoints[0], &core.Result{Success: true, Connected: true, Duration: time.Millisecond, Timestamp: time.Now()})
|
||||
watchdog.UpdateEndpointStatuses(cfg.Endpoints[1], &core.Result{Success: false, Connected: false, Duration: time.Second, Timestamp: time.Now()})
|
||||
router := CreateRouter("../../web/static", cfg.Security, nil, cfg.Metrics)
|
||||
type Scenario struct {
|
||||
Name string
|
||||
@ -89,6 +89,21 @@ func TestUptimeBadge(t *testing.T) {
|
||||
Path: "/api/v1/endpoints/invalid_key/response-times/7d/badge.svg",
|
||||
ExpectedCode: http.StatusNotFound,
|
||||
},
|
||||
{
|
||||
Name: "badge-health-up",
|
||||
Path: "/api/v1/endpoints/core_frontend/health/badge.svg",
|
||||
ExpectedCode: http.StatusOK,
|
||||
},
|
||||
{
|
||||
Name: "badge-health-down",
|
||||
Path: "/api/v1/endpoints/core_backend/health/badge.svg",
|
||||
ExpectedCode: http.StatusOK,
|
||||
},
|
||||
{
|
||||
Name: "badge-health-for-invalid-key",
|
||||
Path: "/api/v1/endpoints/invalid_key/health/badge.svg",
|
||||
ExpectedCode: http.StatusNotFound,
|
||||
},
|
||||
{
|
||||
Name: "chart-response-time-24h",
|
||||
Path: "/api/v1/endpoints/core_backend/response-times/24h/chart.svg",
|
||||
@ -219,3 +234,30 @@ func TestGetBadgeColorFromResponseTime(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetBadgeColorFromHealth(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
HealthStatus string
|
||||
ExpectedColor string
|
||||
}{
|
||||
{
|
||||
HealthStatus: HealthStatusUp,
|
||||
ExpectedColor: badgeColorHexAwesome,
|
||||
},
|
||||
{
|
||||
HealthStatus: HealthStatusDown,
|
||||
ExpectedColor: badgeColorHexVeryBad,
|
||||
},
|
||||
{
|
||||
HealthStatus: HealthStatusUnknown,
|
||||
ExpectedColor: badgeColorHexPassable,
|
||||
},
|
||||
}
|
||||
for _, scenario := range scenarios {
|
||||
t.Run("health-"+scenario.HealthStatus, func(t *testing.T) {
|
||||
if getBadgeColorFromHealth(scenario.HealthStatus) != scenario.ExpectedColor {
|
||||
t.Errorf("expected %s from %s, got %v", scenario.ExpectedColor, scenario.HealthStatus, getBadgeColorFromHealth(scenario.HealthStatus))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user