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

Commit

Permalink
test: add unit test case for core.go
Browse files Browse the repository at this point in the history
Signed-off-by: Guangwen Feng <[email protected]>
  • Loading branch information
Guangwen Feng committed Mar 24, 2020
1 parent bae7528 commit 0f41f77
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions dfget/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"

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

func (s *CoreTestSuite) TestCalculateTimeout(c *check.C) {
cfg := s.createConfig(&bytes.Buffer{})

timeout := calculateTimeout(nil)
c.Assert(timeout, check.Equals, config.DefaultDownloadTimeout)

timeout = calculateTimeout(cfg)
c.Assert(timeout, check.Equals, config.DefaultDownloadTimeout)

cfg.RV.FileLength = 1000
timeout = calculateTimeout(cfg)
c.Assert(timeout, check.Equals, 10*time.Second)

cfg.Timeout = time.Minute
timeout = calculateTimeout(cfg)
c.Assert(timeout, check.Equals, time.Minute)
}

// ----------------------------------------------------------------------------
// helper functions

Expand Down

0 comments on commit 0f41f77

Please sign in to comment.