mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
* created roadmap and yaml claude agent * Update roadmap.md * chore(deps): bump sigstore/cosign-installer from 3.9.2 to 3.10.0 (#1857) Bumps [sigstore/cosign-installer](https://github.com/sigstore/cosign-installer) from 3.9.2 to 3.10.0. - [Release notes](https://github.com/sigstore/cosign-installer/releases) - [Commits](https://github.com/sigstore/cosign-installer/compare/v3.9.2...v3.10.0) --- updated-dependencies: - dependency-name: sigstore/cosign-installer dependency-version: 3.10.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump the security group with 2 updates (#1858) Bumps the security group with 2 updates: [github.com/vmware-tanzu/velero](https://github.com/vmware-tanzu/velero) and [helm.sh/helm/v3](https://github.com/helm/helm). Updates `github.com/vmware-tanzu/velero` from 1.16.2 to 1.17.0 - [Release notes](https://github.com/vmware-tanzu/velero/releases) - [Changelog](https://github.com/vmware-tanzu/velero/blob/main/CHANGELOG.md) - [Commits](https://github.com/vmware-tanzu/velero/compare/v1.16.2...v1.17.0) Updates `helm.sh/helm/v3` from 3.18.6 to 3.19.0 - [Release notes](https://github.com/helm/helm/releases) - [Commits](https://github.com/helm/helm/compare/v3.18.6...v3.19.0) --- updated-dependencies: - dependency-name: github.com/vmware-tanzu/velero dependency-version: 1.17.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security - dependency-name: helm.sh/helm/v3 dependency-version: 3.19.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump helm.sh/helm/v3 from 3.18.6 to 3.19.0 in /examples/sdk/helm-template in the security group (#1859) chore(deps): bump helm.sh/helm/v3 Bumps the security group in /examples/sdk/helm-template with 1 update: [helm.sh/helm/v3](https://github.com/helm/helm). Updates `helm.sh/helm/v3` from 3.18.6 to 3.19.0 - [Release notes](https://github.com/helm/helm/releases) - [Commits](https://github.com/helm/helm/compare/v3.18.6...v3.19.0) --- updated-dependencies: - dependency-name: helm.sh/helm/v3 dependency-version: 3.19.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: security ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add cron job support bundle scheduler Complete implementation with K8s integration: - pkg/schedule/job.go: Job management and persistence - pkg/schedule/daemon.go: Real-time scheduler daemon - pkg/schedule/cli.go: CLI commands (create, list, delete, daemon) - pkg/schedule/schedule_test.go: Comprehensive unit tests - cmd/troubleshoot/cli/root.go: CLI integration * fixing bugbot * Fix all bugbot errors: auto-update stability, job cooldown timing, and daemon execution * Deleting Agent * removed unused flags * fixing auto-upload * fixing markdown files * namespace not required flag for auto collectors to work * loosened cron job validation * writes logs to logfile * fix: resolve autoFromEnv variable scoping issue for CI - Ensure autoFromEnv variable and its usage are in correct scope - Fix build errors: declared and not used / undefined variable - All functionality preserved and tested locally - Force add to override gitignore --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Noah Campbell <noah.edward.campbell@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
125 lines
2.7 KiB
Go
125 lines
2.7 KiB
Go
package schedule
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestManager_CreateJob(t *testing.T) {
|
|
// Use temporary directory for testing
|
|
tempDir, err := os.MkdirTemp("", "schedule-test")
|
|
if err != nil {
|
|
t.Fatalf("Failed to create temp dir: %v", err)
|
|
}
|
|
defer os.RemoveAll(tempDir)
|
|
|
|
manager := &Manager{storageDir: tempDir}
|
|
|
|
// Test job creation
|
|
job, err := manager.CreateJob("test-job", "0 2 * * *", "default", true, "s3://bucket")
|
|
if err != nil {
|
|
t.Fatalf("CreateJob failed: %v", err)
|
|
}
|
|
|
|
if job.Name != "test-job" {
|
|
t.Errorf("Job name = %s, want test-job", job.Name)
|
|
}
|
|
|
|
if job.Schedule != "0 2 * * *" {
|
|
t.Errorf("Schedule = %s, want 0 2 * * *", job.Schedule)
|
|
}
|
|
|
|
if !job.Enabled {
|
|
t.Error("Job should be enabled by default")
|
|
}
|
|
}
|
|
|
|
func TestManager_ListJobs(t *testing.T) {
|
|
tempDir, err := os.MkdirTemp("", "schedule-test")
|
|
if err != nil {
|
|
t.Fatalf("Failed to create temp dir: %v", err)
|
|
}
|
|
defer os.RemoveAll(tempDir)
|
|
|
|
manager := &Manager{storageDir: tempDir}
|
|
|
|
// Create test jobs
|
|
_, err = manager.CreateJob("job1", "0 1 * * *", "ns1", false, "")
|
|
if err != nil {
|
|
t.Fatalf("CreateJob failed: %v", err)
|
|
}
|
|
|
|
_, err = manager.CreateJob("job2", "0 2 * * *", "ns2", true, "s3://bucket")
|
|
if err != nil {
|
|
t.Fatalf("CreateJob failed: %v", err)
|
|
}
|
|
|
|
// List jobs
|
|
jobs, err := manager.ListJobs()
|
|
if err != nil {
|
|
t.Fatalf("ListJobs failed: %v", err)
|
|
}
|
|
|
|
if len(jobs) != 2 {
|
|
t.Errorf("Expected 2 jobs, got %d", len(jobs))
|
|
}
|
|
}
|
|
|
|
func TestManager_DeleteJob(t *testing.T) {
|
|
tempDir, err := os.MkdirTemp("", "schedule-test")
|
|
if err != nil {
|
|
t.Fatalf("Failed to create temp dir: %v", err)
|
|
}
|
|
defer os.RemoveAll(tempDir)
|
|
|
|
manager := &Manager{storageDir: tempDir}
|
|
|
|
// Create and delete job
|
|
job, err := manager.CreateJob("temp-job", "0 3 * * *", "default", false, "")
|
|
if err != nil {
|
|
t.Fatalf("CreateJob failed: %v", err)
|
|
}
|
|
|
|
err = manager.DeleteJob(job.Name)
|
|
if err != nil {
|
|
t.Fatalf("DeleteJob failed: %v", err)
|
|
}
|
|
|
|
// Verify deletion
|
|
jobs, err := manager.ListJobs()
|
|
if err != nil {
|
|
t.Fatalf("ListJobs failed: %v", err)
|
|
}
|
|
|
|
if len(jobs) != 0 {
|
|
t.Errorf("Expected 0 jobs after deletion, got %d", len(jobs))
|
|
}
|
|
}
|
|
|
|
func TestDaemon_ScheduleMatching(t *testing.T) {
|
|
daemon, err := NewDaemon()
|
|
if err != nil {
|
|
t.Fatalf("NewDaemon failed: %v", err)
|
|
}
|
|
|
|
// Test job that should run at current minute
|
|
now := time.Now()
|
|
job := &Job{
|
|
Schedule: fmt.Sprintf("%d %d * * *", now.Minute(), now.Hour()),
|
|
LastRun: time.Time{}, // Never run
|
|
Enabled: true,
|
|
}
|
|
|
|
if !daemon.shouldJobRun(job, now) {
|
|
t.Error("Job should run at current time")
|
|
}
|
|
|
|
// Test job that just ran
|
|
job.LastRun = now.Add(-25 * time.Second)
|
|
if daemon.shouldJobRun(job, now) {
|
|
t.Error("Job should not run again so soon")
|
|
}
|
|
}
|