@@ -5,7 +5,7 @@ package agent
55import (
66 "bytes"
77 "errors"
8- "io/ioutil "
8+ "io"
99 "net/http"
1010 "time"
1111
@@ -145,7 +145,7 @@ var _ = Describe("Infra/Agent/Version", func() {
145145 p .runtimeOS = "darwin"
146146 p .httpGetter = func (wrapper httpHelper.RequestWrapper ) (* http.Response , error ) {
147147 return & http.Response {
148- Body : ioutil .NopCloser (bytes .NewReader ([]byte (`{"published_at": "2022-11-17T10:50:43Z"}` ))),
148+ Body : io .NopCloser (bytes .NewReader ([]byte (`{"published_at": "2022-11-17T10:50:43Z"}` ))),
149149 }, nil
150150 }
151151 p .now = func () time.Time { return time .Date (2022 , time .Month (11 ), 21 , 1 , 10 , 30 , 0 , time .UTC ) }
@@ -180,7 +180,7 @@ var _ = Describe("Infra/Agent/Version", func() {
180180 p .runtimeOS = "darwin"
181181 p .httpGetter = func (wrapper httpHelper.RequestWrapper ) (* http.Response , error ) {
182182 return & http.Response {
183- Body : ioutil .NopCloser (bytes .NewReader ([]byte (`{"published_at": "2020-11-17T10:50:43Z"}` ))),
183+ Body : io .NopCloser (bytes .NewReader ([]byte (`{"published_at": "2020-11-17T10:50:43Z"}` ))),
184184 }, nil
185185 }
186186 p .now = func () time.Time { return time .Date (2022 , time .Month (11 ), 21 , 1 , 10 , 30 , 0 , time .UTC ) }
@@ -355,13 +355,15 @@ var _ = Describe("Infra/Agent/Version", func() {
355355 var (
356356 version tasks.Ver
357357 err error
358+ options tasks.Options
358359 )
359360
360361 JustBeforeEach (func () {
361- err = p .validatePublishDate (version )
362+ err = p .validatePublishDate (version , options )
362363 })
363364 Context ("Version prior to 1.12.0" , func () {
364365 BeforeEach (func () {
366+ options = tasks.Options {}
365367 version = tasks.Ver {Major : 1 , Minor : 11 , Patch : 0 , Build : 0 }
366368 })
367369
@@ -372,10 +374,11 @@ var _ = Describe("Infra/Agent/Version", func() {
372374
373375 Context ("Up-to-date version" , func () {
374376 BeforeEach (func () {
377+ options = tasks.Options {}
375378 version = tasks.Ver {Major : 1 , Minor : 33 , Patch : 0 , Build : 0 }
376379 p .httpGetter = func (wrapper httpHelper.RequestWrapper ) (* http.Response , error ) {
377380 return & http.Response {
378- Body : ioutil .NopCloser (bytes .NewReader ([]byte (`{"published_at": "2021-11-22T10:50:43Z"}` ))),
381+ Body : io .NopCloser (bytes .NewReader ([]byte (`{"published_at": "2021-11-22T10:50:43Z"}` ))),
379382 }, nil
380383 }
381384 p .now = func () time.Time { return time .Date (2022 , time .Month (11 ), 21 , 1 , 10 , 30 , 0 , time .UTC ) }
@@ -385,6 +388,39 @@ var _ = Describe("Infra/Agent/Version", func() {
385388 Expect (err ).To (BeNil ())
386389 })
387390 })
391+
392+ Context ("releaseDateOverride option is provided" , func () {
393+ BeforeEach (func () {
394+ version = tasks.Ver {Major : 1 , Minor : 77 , Patch : 1 , Build : 0 }
395+ options = tasks.Options {Options : map [string ]string {releaseDateOverrideKey : "2026-07-13T18:04:00Z" }}
396+ p .now = func () time.Time { return time .Date (2026 , time .Month (7 ), 13 , 18 , 5 , 0 , 0 , time .UTC ) }
397+ p .httpGetter = func (wrapper httpHelper.RequestWrapper ) (* http.Response , error ) {
398+ Fail ("httpGetter must not be called when releaseDateOverride is set" )
399+ return nil , nil
400+ }
401+ })
402+
403+ It ("should not return an error and should not hit the network" , func () {
404+ Expect (err ).To (BeNil ())
405+ })
406+ })
407+
408+ Context ("releaseDateOverride option is empty" , func () {
409+ BeforeEach (func () {
410+ version = tasks.Ver {Major : 1 , Minor : 33 , Patch : 0 , Build : 0 }
411+ options = tasks.Options {Options : map [string ]string {releaseDateOverrideKey : "" }}
412+ p .httpGetter = func (wrapper httpHelper.RequestWrapper ) (* http.Response , error ) {
413+ return & http.Response {
414+ Body : io .NopCloser (bytes .NewReader ([]byte (`{"published_at": "2021-11-22T10:50:43Z"}` ))),
415+ }, nil
416+ }
417+ p .now = func () time.Time { return time .Date (2022 , time .Month (11 ), 21 , 1 , 10 , 30 , 0 , time .UTC ) }
418+ })
419+
420+ It ("should fall back to the GitHub API path" , func () {
421+ Expect (err ).To (BeNil ())
422+ })
423+ })
388424 })
389425 })
390426})
0 commit comments