Skip to content

Commit

Permalink
update gronx dep and fix scaler tests (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shareed2k authored Jul 8, 2024
1 parent 8823b59 commit 3718ccf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaler/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type (
lastScaleDown time.Time
lastScaleUp time.Time
logger *log.Entry
schedule gronx.Gronx
schedule *gronx.Gronx
metrics *Metrics
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/scaler/scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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),
}
})
Expand Down Expand Up @@ -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))
Expand Down
28 changes: 28 additions & 0 deletions pkg/testing/mocks/schedule/checker.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 3718ccf

Please sign in to comment.