mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-22 07:53:38 +01:00
82 lines
2.9 KiB
Go
82 lines
2.9 KiB
Go
package paging
|
|
|
|
import "testing"
|
|
|
|
func TestNewServiceStatusParams(t *testing.T) {
|
|
type Scenario struct {
|
|
Name string
|
|
Params *ServiceStatusParams
|
|
ExpectedEventsPage int
|
|
ExpectedEventsPageSize int
|
|
ExpectedResultsPage int
|
|
ExpectedResultsPageSize int
|
|
ExpectedIncludeUptime bool
|
|
}
|
|
scenarios := []Scenario{
|
|
{
|
|
Name: "empty-params",
|
|
Params: NewServiceStatusParams(),
|
|
ExpectedEventsPage: 0,
|
|
ExpectedEventsPageSize: 0,
|
|
ExpectedResultsPage: 0,
|
|
ExpectedResultsPageSize: 0,
|
|
ExpectedIncludeUptime: false,
|
|
},
|
|
{
|
|
Name: "with-events-page-2-size-7",
|
|
Params: NewServiceStatusParams().WithEvents(2, 7),
|
|
ExpectedEventsPage: 2,
|
|
ExpectedEventsPageSize: 7,
|
|
ExpectedResultsPage: 0,
|
|
ExpectedResultsPageSize: 0,
|
|
ExpectedIncludeUptime: false,
|
|
},
|
|
{
|
|
Name: "with-events-page-4-size-3-uptime",
|
|
Params: NewServiceStatusParams().WithEvents(4, 3).WithUptime(),
|
|
ExpectedEventsPage: 4,
|
|
ExpectedEventsPageSize: 3,
|
|
ExpectedResultsPage: 0,
|
|
ExpectedResultsPageSize: 0,
|
|
ExpectedIncludeUptime: true,
|
|
},
|
|
{
|
|
Name: "with-results-page-1-size-20-uptime",
|
|
Params: NewServiceStatusParams().WithResults(1, 20).WithUptime(),
|
|
ExpectedEventsPage: 0,
|
|
ExpectedEventsPageSize: 0,
|
|
ExpectedResultsPage: 1,
|
|
ExpectedResultsPageSize: 20,
|
|
ExpectedIncludeUptime: true,
|
|
},
|
|
{
|
|
Name: "with-results-page-2-size-10-events-page-3-size-50",
|
|
Params: NewServiceStatusParams().WithResults(2, 10).WithEvents(3, 50),
|
|
ExpectedEventsPage: 3,
|
|
ExpectedEventsPageSize: 50,
|
|
ExpectedResultsPage: 2,
|
|
ExpectedResultsPageSize: 10,
|
|
ExpectedIncludeUptime: false,
|
|
},
|
|
}
|
|
for _, scenario := range scenarios {
|
|
t.Run(scenario.Name, func(t *testing.T) {
|
|
if scenario.Params.EventsPage != scenario.ExpectedEventsPage {
|
|
t.Errorf("expected ExpectedEventsPage to be %d, was %d", scenario.ExpectedEventsPageSize, scenario.Params.EventsPage)
|
|
}
|
|
if scenario.Params.EventsPageSize != scenario.ExpectedEventsPageSize {
|
|
t.Errorf("expected EventsPageSize to be %d, was %d", scenario.ExpectedEventsPageSize, scenario.Params.EventsPageSize)
|
|
}
|
|
if scenario.Params.ResultsPage != scenario.ExpectedResultsPage {
|
|
t.Errorf("expected ResultsPage to be %d, was %d", scenario.ExpectedResultsPage, scenario.Params.ResultsPage)
|
|
}
|
|
if scenario.Params.ResultsPageSize != scenario.ExpectedResultsPageSize {
|
|
t.Errorf("expected ResultsPageSize to be %d, was %d", scenario.ExpectedResultsPageSize, scenario.Params.ResultsPageSize)
|
|
}
|
|
if scenario.Params.IncludeUptime != scenario.ExpectedIncludeUptime {
|
|
t.Errorf("expected IncludeUptime to be %v, was %v", scenario.ExpectedIncludeUptime, scenario.Params.IncludeUptime)
|
|
}
|
|
})
|
|
}
|
|
}
|