Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit 79fd076

Browse files
authored
Merge pull request #1260 from fenggw-fnst/work
test: add unit test case for core.go
2 parents 7179243 + 0f41f77 commit 79fd076

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

dfget/core/core_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"path/filepath"
2828
"strings"
2929
"testing"
30+
"time"
3031

3132
"github.com/dragonflyoss/Dragonfly/dfget/config"
3233
. "github.com/dragonflyoss/Dragonfly/dfget/core/helper"
@@ -139,6 +140,24 @@ func (s *CoreTestSuite) TestCheckConnectSupernode(c *check.C) {
139140
c.Assert(ip, check.Equals, "")
140141
}
141142

143+
func (s *CoreTestSuite) TestCalculateTimeout(c *check.C) {
144+
cfg := s.createConfig(&bytes.Buffer{})
145+
146+
timeout := calculateTimeout(nil)
147+
c.Assert(timeout, check.Equals, config.DefaultDownloadTimeout)
148+
149+
timeout = calculateTimeout(cfg)
150+
c.Assert(timeout, check.Equals, config.DefaultDownloadTimeout)
151+
152+
cfg.RV.FileLength = 1000
153+
timeout = calculateTimeout(cfg)
154+
c.Assert(timeout, check.Equals, 10*time.Second)
155+
156+
cfg.Timeout = time.Minute
157+
timeout = calculateTimeout(cfg)
158+
c.Assert(timeout, check.Equals, time.Minute)
159+
}
160+
142161
// ----------------------------------------------------------------------------
143162
// helper functions
144163

0 commit comments

Comments
 (0)