Skip to content

Commit e010e64

Browse files
committed
fix: the unit testing is failed
1 parent ec90fa5 commit e010e64

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

cmd/get.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ type downloadOption struct {
100100
MaxAttempts int
101101
AcceptPreRelease bool
102102
RoundTripper http.RoundTripper
103-
Username string
104-
Password string
103+
Username string
104+
Password string
105105
Magnet bool
106106
Force bool
107107
Mod int

pkg/net/http_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"os"
99
"testing"
10+
"time"
1011

1112
"github.com/linuxsuren/http-downloader/mock/mhttp"
1213
"github.com/linuxsuren/http-downloader/pkg/net"
@@ -139,6 +140,9 @@ var _ = Describe("http test", func() {
139140
Debug: true,
140141
TargetFilePath: debugFile,
141142
}
143+
defer func() {
144+
_ = os.RemoveAll(debugFile)
145+
}()
142146

143147
request, _ := http.NewRequest(http.MethodGet, "", nil)
144148
response := &http.Response{
@@ -153,7 +157,7 @@ var _ = Describe("http test", func() {
153157
Expect(err).To(HaveOccurred())
154158

155159
_, err = os.Stat(debugFile)
156-
Expect(err).NotTo(BeNil())
160+
Expect(err).To(BeNil())
157161
})
158162

159163
It("showProgress", func() {
@@ -251,7 +255,8 @@ func TestDetectSize(t *testing.T) {
251255
roundTripper.EXPECT().
252256
RoundTrip(mockRequest).Return(mockResponse, nil)
253257

254-
total, rangeSupport, err := net.DetectSizeWithRoundTripper(targetURL, os.TempDir(), false, false, false, roundTripper, 0)
258+
fileName := fmt.Sprintf("%s-%d", os.TempDir(), time.Now().Second())
259+
total, rangeSupport, err := net.DetectSizeWithRoundTripper(targetURL, fileName, false, false, false, roundTripper, 0)
255260
assert.Nil(t, err)
256261
assert.Equal(t, int64(102), total)
257262
assert.True(t, rangeSupport)

0 commit comments

Comments
 (0)