diff --git a/go.mod b/go.mod index 48021ff..65c7e8f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bringg/jenkins-autoscaler go 1.22 require ( - github.com/adhocore/gronx v1.1.2 + github.com/adhocore/gronx v1.8.1 github.com/adrg/xdg v0.4.0 github.com/aws/aws-sdk-go-v2 v1.30.1 github.com/aws/aws-sdk-go-v2/config v1.27.24 diff --git a/go.sum b/go.sum index 1ffb8b0..7f02e3b 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,8 @@ github.com/OpenPeeDeeP/depguard/v2 v2.2.0 h1:vDfG60vDtIuf0MEOhmLlLLSzqaRM8EMcgJP github.com/OpenPeeDeeP/depguard/v2 v2.2.0/go.mod h1:CIzddKRvLBC4Au5aYP/i3nyaWQ+ClszLIuVocRiCYFQ= github.com/Shareed2k/gojenkins v0.0.0-20230110213508-e358f2d2548d h1:2oBcduxg8lQKNlfLgaxUQgnnIX96QfXUL27P1R3ZiIU= github.com/Shareed2k/gojenkins v0.0.0-20230110213508-e358f2d2548d/go.mod h1:kfW4UFryDa6Jy2d+U3dfZEG9SvwUE9mpkWDWnTE+74g= -github.com/adhocore/gronx v1.1.2 h1:Hgm+d8SyGtn+rCoDkxZq3nLNFLLkzRGR7L2ziRRD1w8= -github.com/adhocore/gronx v1.1.2/go.mod h1:7oUY1WAU8rEJWmAxXR2DN0JaO4gi9khSgKjiRypqteg= +github.com/adhocore/gronx v1.8.1 h1:F2mLTG5sB11z7vplwD4iydz3YCEjstSfYmCrdSm3t6A= +github.com/adhocore/gronx v1.8.1/go.mod h1:7oUY1WAU8rEJWmAxXR2DN0JaO4gi9khSgKjiRypqteg= github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E= github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk= diff --git a/pkg/scaler/scaler.go b/pkg/scaler/scaler.go index 2aba4d0..fa89cab 100644 --- a/pkg/scaler/scaler.go +++ b/pkg/scaler/scaler.go @@ -33,7 +33,7 @@ type ( lastScaleDown time.Time lastScaleUp time.Time logger *log.Entry - schedule gronx.Gronx + schedule *gronx.Gronx metrics *Metrics } diff --git a/pkg/scaler/scaler_test.go b/pkg/scaler/scaler_test.go index 0e27d2f..52750b6 100644 --- a/pkg/scaler/scaler_test.go +++ b/pkg/scaler/scaler_test.go @@ -25,6 +25,7 @@ import ( jclient "github.com/bringg/jenkins-autoscaler/pkg/scaler/client" mock_backend "github.com/bringg/jenkins-autoscaler/pkg/testing/mocks/backend" mock_client "github.com/bringg/jenkins-autoscaler/pkg/testing/mocks/scaler" + schedule_test "github.com/bringg/jenkins-autoscaler/pkg/testing/mocks/schedule" ) var _ = g.Describe("Scaler", func() { @@ -74,6 +75,7 @@ var _ = g.Describe("Scaler", func() { scal, err = New(cfg, bk, logger, metrics) o.Expect(err).To(o.Not(o.HaveOccurred())) scal.client = client + scal.schedule = &gronx.Gronx{C: schedule_test.NewFakeSegmentChecker()} }) g.AfterEach(func() { @@ -436,7 +438,7 @@ var _ = g.Describe("Scaler", func() { ScaleDownGracePeriodDuringWorkingHours: fs.Duration(time.Minute * 1), WorkingHoursCronExpressions: "* * * * *", }, - schedule: gronx.New(), + schedule: &gronx.Gronx{C: schedule_test.NewFakeSegmentChecker()}, logger: logrus.NewEntry(logger), } }) @@ -663,7 +665,7 @@ var _ = g.Describe("Scaler", func() { scal := Scaler{ logger: logrus.NewEntry(logger), opt: opt, - schedule: gronx.New(), + schedule: &gronx.Gronx{C: schedule_test.NewFakeSegmentChecker()}, } o.Expect(scal.isMinimumNodes(MakeFakeNodes(numNodes))).To(o.Equal(result)) diff --git a/pkg/testing/mocks/schedule/checker.go b/pkg/testing/mocks/schedule/checker.go new file mode 100644 index 0000000..240998d --- /dev/null +++ b/pkg/testing/mocks/schedule/checker.go @@ -0,0 +1,28 @@ +package schedule + +import ( + "time" + + "github.com/adhocore/gronx" +) + +type FakeSegmentChecker struct { + checker gronx.Checker +} + +func NewFakeSegmentChecker() *FakeSegmentChecker { + checker := &gronx.SegmentChecker{} + checker.SetRef(time.Date(2024, time.July, 1, 1, 1, 0, 0, time.UTC)) + + return &FakeSegmentChecker{checker} +} + +func (c *FakeSegmentChecker) GetRef() time.Time { + return c.checker.GetRef() +} + +func (c *FakeSegmentChecker) SetRef(_ time.Time) {} + +func (c *FakeSegmentChecker) CheckDue(segment string, pos int) (due bool, err error) { + return c.checker.CheckDue(segment, pos) +}