mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-24 17:04:42 +01:00
f54c45e20e
* refactor: Move SSH outside of endpoint.go * refactor: Use pointers for Alert receivers * feat: Implement push-based external endpoints * Fix failing tests * Validate external endpoints on start * Add tests for external endpoints * refactor some error equality checks * Improve docs and refactor some code * Fix UI-related issues with external endpoints
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package core
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/TwiN/gatus/v5/alerting/alert"
|
|
)
|
|
|
|
func TestValidateEndpointNameGroupAndAlerts(t *testing.T) {
|
|
scenarios := []struct {
|
|
name string
|
|
group string
|
|
alerts []*alert.Alert
|
|
expectedErr error
|
|
}{
|
|
{
|
|
name: "n",
|
|
group: "g",
|
|
alerts: []*alert.Alert{{Type: "slack"}},
|
|
},
|
|
{
|
|
name: "n",
|
|
alerts: []*alert.Alert{{Type: "slack"}},
|
|
},
|
|
{
|
|
group: "g",
|
|
alerts: []*alert.Alert{{Type: "slack"}},
|
|
expectedErr: ErrEndpointWithNoName,
|
|
},
|
|
{
|
|
name: "\"",
|
|
alerts: []*alert.Alert{{Type: "slack"}},
|
|
expectedErr: ErrEndpointWithInvalidNameOrGroup,
|
|
},
|
|
{
|
|
name: "n",
|
|
group: "\\",
|
|
alerts: []*alert.Alert{{Type: "slack"}},
|
|
expectedErr: ErrEndpointWithInvalidNameOrGroup,
|
|
},
|
|
}
|
|
for _, scenario := range scenarios {
|
|
t.Run(scenario.name, func(t *testing.T) {
|
|
err := validateEndpointNameGroupAndAlerts(scenario.name, scenario.group, scenario.alerts)
|
|
if !errors.Is(err, scenario.expectedErr) {
|
|
t.Errorf("expected error to be %v but got %v", scenario.expectedErr, err)
|
|
}
|
|
})
|
|
}
|
|
}
|