MCPcopy Index your code
hub / github.com/docker/docker-agent / TestParseRetryAfterHeader

Function TestParseRetryAfterHeader

pkg/modelerrors/modelerrors_test.go:648–687  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

646}
647
648func TestParseRetryAfterHeader(t *testing.T) {
649 t.Parallel()
650
651 tests := []struct {
652 name string
653 value string
654 expected time.Duration
655 }{
656 {name: "empty", value: "", expected: 0},
657 {name: "zero seconds", value: "0", expected: 0},
658 {name: "negative seconds", value: "-1", expected: 0},
659 {name: "invalid string", value: "foo", expected: 0},
660 {name: "5 seconds", value: "5", expected: 5 * time.Second},
661 {name: "30 seconds", value: "30", expected: 30 * time.Second},
662 {name: "120 seconds", value: "120", expected: 120 * time.Second},
663 }
664
665 for _, tt := range tests {
666 t.Run(tt.name, func(t *testing.T) {
667 t.Parallel()
668 got := parseRetryAfterHeader(tt.value)
669 assert.Equal(t, tt.expected, got, "parseRetryAfterHeader(%q)", tt.value)
670 })
671 }
672
673 t.Run("HTTP-date in the future", func(t *testing.T) {
674 t.Parallel()
675 future := time.Now().Add(10 * time.Second).UTC().Format(http.TimeFormat)
676 got := parseRetryAfterHeader(future)
677 assert.Greater(t, got, 0*time.Second, "should return positive duration for future HTTP-date")
678 assert.LessOrEqual(t, got, 11*time.Second, "should not exceed ~10s for near-future date")
679 })
680
681 t.Run("HTTP-date in the past", func(t *testing.T) {
682 t.Parallel()
683 past := time.Now().Add(-10 * time.Second).UTC().Format(http.TimeFormat)
684 got := parseRetryAfterHeader(past)
685 assert.Equal(t, 0*time.Second, got, "should return 0 for past HTTP-date")
686 })
687}
688
689func TestStatusError(t *testing.T) {
690 t.Parallel()

Callers

nothing calls this directly

Calls 4

parseRetryAfterHeaderFunction · 0.85
NowMethod · 0.80
RunMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected