Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/crontab.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type TimezoneLocationName struct {
type Crontab struct {
User string `json:"-"`
IsUserCrontab bool `json:"isUserCrontab"`
IsSaved bool `json:"-"`
Filename string `json:"filename"`
Lines []*Line `json:"-"`
TimezoneLocationName *TimezoneLocationName `json:"timezone,omitempty"`
Expand Down Expand Up @@ -272,7 +271,7 @@ func (c Crontab) Write() string {
return result
}

func (c Crontab) Save(crontabLines string) error {
func (c *Crontab) Save(crontabLines string) error {
if c.IsUserCrontab {
cmd := c.buildCrontabCommand("-")

Expand All @@ -290,7 +289,6 @@ func (c Crontab) Save(crontabLines string) error {
}
}

c.IsSaved = true
return nil
}

Expand Down Expand Up @@ -920,7 +918,6 @@ func (c *Crontab) lightweightCopy() Crontab {
return Crontab{
User: c.User,
IsUserCrontab: c.IsUserCrontab,
IsSaved: c.IsSaved,
Filename: c.Filename,
Lines: nil, // Explicitly nil to break circular reference
TimezoneLocationName: c.TimezoneLocationName,
Expand Down
1 change: 1 addition & 0 deletions lib/crontab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func TestLineWriteWithEnvFlag(t *testing.T) {
viper.Set("CRONITOR_ENV", originalEnv)
}


func TestLineWriteWithNoStdoutAndEnv(t *testing.T) {
// Save original viper value
originalEnv := viper.GetString("CRONITOR_ENV")
Expand Down
2 changes: 0 additions & 2 deletions lib/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"math/rand"
"os"
"path/filepath"
"time"
)

func randomMinute() int {
rand.Seed(time.Now().Unix())
return rand.Intn(59)
}

Expand Down
28 changes: 28 additions & 0 deletions lib/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package lib

import (
"testing"
)

func TestRandomMinuteRange(t *testing.T) {
// Verify randomMinute returns values in the valid range [0, 59)
for i := 0; i < 100; i++ {
result := randomMinute()
if result < 0 || result >= 59 {
t.Errorf("randomMinute() returned %d, expected value in range [0, 59)", result)
}
}
}

func TestRandomMinuteNotConstant(t *testing.T) {
// Verify randomMinute produces varying output (not stuck on a single value).
// With 20 calls, getting the same value every time is astronomically unlikely
// if the RNG is properly seeded.
seen := make(map[int]bool)
for i := 0; i < 20; i++ {
seen[randomMinute()] = true
}
if len(seen) < 2 {
t.Errorf("randomMinute() returned the same value %d times in a row, RNG may not be working", 20)
}
}
Loading