feat(suite): Implement Suites (#1239)
* feat(suite): Implement Suites Fixes #1230 * Update docs * Fix variable alignment * Prevent always-run endpoint from running if a context placeholder fails to resolve in the URL * Return errors when a context placeholder path fails to resolve * Add a couple of unit tests * Add a couple of unit tests * fix(ui): Update group count properly Fixes #1233 * refactor: Pass down entire config instead of several sub-configs * fix: Change default suite interval and timeout * fix: Deprecate disable-monitoring-lock in favor of concurrency * fix: Make sure there are no duplicate keys * Refactor some code * Update watchdog/watchdog.go * Update web/app/src/components/StepDetailsModal.vue Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: Remove useless log * fix: Set default concurrency to 3 instead of 5 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
1 parent
10cabb9dde
commit
d668a14703
74 files changed
+7513
-652
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/TwiN/gatus/v5/config/endpoint"
|
||||
"github.com/TwiN/gatus/v5/config/suite"
|
||||
"github.com/TwiN/gatus/v5/storage"
|
||||
"github.com/TwiN/gatus/v5/storage/store/common/paging"
|
||||
)
|
||||
@@ -64,3 +65,108 @@ func TestShallowCopyEndpointStatus(t *testing.T) {
|
||||
t.Error("expected to have 25 results, because there's only 25 results")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShallowCopySuiteStatus(t *testing.T) {
|
||||
testSuite := &suite.Suite{Name: "test-suite", Group: "test-group"}
|
||||
suiteStatus := &suite.Status{
|
||||
Name: testSuite.Name,
|
||||
Group: testSuite.Group,
|
||||
Key: testSuite.Key(),
|
||||
Results: []*suite.Result{},
|
||||
}
|
||||
|
||||
ts := time.Now().Add(-25 * time.Hour)
|
||||
for i := 0; i < 25; i++ {
|
||||
result := &suite.Result{
|
||||
Name: testSuite.Name,
|
||||
Group: testSuite.Group,
|
||||
Success: i%2 == 0,
|
||||
Timestamp: ts,
|
||||
Duration: time.Duration(i*10) * time.Millisecond,
|
||||
}
|
||||
suiteStatus.Results = append(suiteStatus.Results, result)
|
||||
ts = ts.Add(time.Hour)
|
||||
}
|
||||
|
||||
t.Run("invalid-page-negative", func(t *testing.T) {
|
||||
result := ShallowCopySuiteStatus(suiteStatus, paging.NewSuiteStatusParams().WithPagination(-1, 10))
|
||||
if len(result.Results) != 0 {
|
||||
t.Errorf("expected 0 results for negative page, got %d", len(result.Results))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("invalid-page-zero", func(t *testing.T) {
|
||||
result := ShallowCopySuiteStatus(suiteStatus, paging.NewSuiteStatusParams().WithPagination(0, 10))
|
||||
if len(result.Results) != 0 {
|
||||
t.Errorf("expected 0 results for zero page, got %d", len(result.Results))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("invalid-pagesize-negative", func(t *testing.T) {
|
||||
result := ShallowCopySuiteStatus(suiteStatus, paging.NewSuiteStatusParams().WithPagination(1, -1))
|
||||
if len(result.Results) != 0 {
|
||||
t.Errorf("expected 0 results for negative page size, got %d", len(result.Results))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("zero-pagesize", func(t *testing.T) {
|
||||
result := ShallowCopySuiteStatus(suiteStatus, paging.NewSuiteStatusParams().WithPagination(1, 0))
|
||||
if len(result.Results) != 0 {
|
||||
t.Errorf("expected 0 results for zero page size, got %d", len(result.Results))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("nil-params", func(t *testing.T) {
|
||||
result := ShallowCopySuiteStatus(suiteStatus, nil)
|
||||
if len(result.Results) != 25 {
|
||||
t.Errorf("expected 25 results for nil params, got %d", len(result.Results))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("zero-params", func(t *testing.T) {
|
||||
result := ShallowCopySuiteStatus(suiteStatus, &paging.SuiteStatusParams{Page: 0, PageSize: 0})
|
||||
if len(result.Results) != 25 {
|
||||
t.Errorf("expected 25 results for zero-value params, got %d", len(result.Results))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("first-page", func(t *testing.T) {
|
||||
result := ShallowCopySuiteStatus(suiteStatus, paging.NewSuiteStatusParams().WithPagination(1, 10))
|
||||
if len(result.Results) != 10 {
|
||||
t.Errorf("expected 10 results for page 1, size 10, got %d", len(result.Results))
|
||||
}
|
||||
// Verify newest results are returned (reverse pagination)
|
||||
if len(result.Results) > 0 && !result.Results[len(result.Results)-1].Timestamp.After(result.Results[0].Timestamp) {
|
||||
t.Error("expected newest result to be at the end")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("second-page", func(t *testing.T) {
|
||||
result := ShallowCopySuiteStatus(suiteStatus, paging.NewSuiteStatusParams().WithPagination(2, 10))
|
||||
if len(result.Results) != 10 {
|
||||
t.Errorf("expected 10 results for page 2, size 10, got %d", len(result.Results))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("last-partial-page", func(t *testing.T) {
|
||||
result := ShallowCopySuiteStatus(suiteStatus, paging.NewSuiteStatusParams().WithPagination(3, 10))
|
||||
if len(result.Results) != 5 {
|
||||
t.Errorf("expected 5 results for page 3, size 10, got %d", len(result.Results))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("beyond-available-pages", func(t *testing.T) {
|
||||
result := ShallowCopySuiteStatus(suiteStatus, paging.NewSuiteStatusParams().WithPagination(4, 10))
|
||||
if len(result.Results) != 0 {
|
||||
t.Errorf("expected 0 results for page beyond available data, got %d", len(result.Results))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("large-page-size", func(t *testing.T) {
|
||||
result := ShallowCopySuiteStatus(suiteStatus, paging.NewSuiteStatusParams().WithPagination(1, 100))
|
||||
if len(result.Results) != 25 {
|
||||
t.Errorf("expected 25 results for large page size, got %d", len(result.Results))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user