Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1272 from Hellcatlk/master
Browse files Browse the repository at this point in the history
Add unit test cases for download_api_test.go&algorithm_test.go&atomiccount_test.go&httpuils_test.go
  • Loading branch information
lowzj authored May 13, 2020
2 parents 2af6a81 + 6da8759 commit 164e390
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
38 changes: 24 additions & 14 deletions client/httpuils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,41 @@ import (

func TestParseHost(t *testing.T) {
tests := []struct {
name string
host string
expect error
name string
host string
expected error
}{
{
name: "http host",
host: "http://github.com",
expect: nil,
name: "tcp host",
host: "tcp://github.com",
expected: nil,
},
{
name: "https host",
host: "https://github.com",
expect: nil,
name: "unix host",
host: "unix://github.com",
expected: nil,
},
{
name: "not support url scheme",
host: "wss://github.com",
expect: errors.New("not support url scheme wss"),
name: "http host",
host: "http://github.com",
expected: nil,
},
{
name: "https host",
host: "https://github.com",
expected: nil,
},
{
name: "not support url scheme",
host: "wss://github.com",
expected: errors.New("not support url scheme wss"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, _, _, err := ParseHost(tt.host)
if (nil == err) != (nil == tt.expect) {
t.Errorf("expect: %v, got: %v\n", tt.expect, err)
if (nil == err) != (nil == tt.expected) {
t.Errorf("expected: %v, got: %v\n", tt.expected, err)
}
})
}
Expand Down
1 change: 1 addition & 0 deletions dfget/core/api/download_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (s *DownloadAPITestSuite) TestGetRealRange(c *check.C) {
rangeValue string
expected string
}{
{"", "0-1", ""},
{"0-1", "", "0-1"},
{"0-1", "1-100", "1-2"},
{"0-100", "1-100", "1-100"},
Expand Down
6 changes: 6 additions & 0 deletions pkg/atomiccount/atomiccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func (suite *AtomicCountUtilSuite) TestAdd(c *check.C) {

result := acount.Get()
c.Check(result, check.Equals, (int32)(12))

var nilAcount *AtomicInt
c.Check(nilAcount.Add(5), check.Equals, (int32)(0))
}

func (suite *AtomicCountUtilSuite) TestSet(c *check.C) {
Expand All @@ -49,4 +52,7 @@ func (suite *AtomicCountUtilSuite) TestSet(c *check.C) {
_ = acount.Set(1)
result := acount.Get()
c.Check(result, check.Equals, (int32)(1))

var nilAcount *AtomicInt
c.Check(nilAcount.Get(), check.Equals, (int32)(0))
}

0 comments on commit 164e390

Please sign in to comment.