Skip to content

Commit a8aad05

Browse files
committed
add(Tests): check is got sending header values to server tests.
1 parent 0b6865d commit a8aad05

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

download_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestGetInfoAndInit(t *testing.T) {
3131
t.Run("getInfoTest", getInfoTest)
3232
t.Run("okInitTest", okInitTest)
3333
t.Run("errInitTest", errInitTest)
34+
t.Run("sendHeadersTest", sendHeadersTest)
3435
}
3536

3637
func TestDownloading(t *testing.T) {
@@ -68,6 +69,35 @@ func getInfoTest(t *testing.T) {
6869
}
6970
}
7071

72+
func sendHeadersTest(t *testing.T) {
73+
74+
tmpFile := createTemp()
75+
defer clean(tmpFile)
76+
77+
dl := got.NewDownload(context.Background(), httpt.URL+"/header_values", tmpFile)
78+
dl.Header = []got.GotHeader{
79+
{
80+
Key: "x-test-header",
81+
Value: "foobar",
82+
},
83+
}
84+
85+
info, err := dl.GetInfo()
86+
87+
if err != nil {
88+
t.Error(err)
89+
return
90+
}
91+
92+
if info.Rangeable == false {
93+
t.Error("rangeable should be true")
94+
}
95+
96+
if info.Size != uint64(okFileStat.Size()) {
97+
t.Errorf("Invalid file size, wants %d but got %d", okFileStat.Size(), info.Size)
98+
}
99+
}
100+
71101
func getFilenameTest(t *testing.T) {
72102

73103
tmpFile := createTemp()

got_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ func NewHttptestServer() *httptest.Server {
5353
http.ServeFile(w, r, "go.mod")
5454
return
5555

56+
case "/header_values":
57+
if r.Header.Get("x-test-header") == "foobar" {
58+
http.ServeFile(w, r, "go.mod")
59+
return
60+
}
61+
62+
w.WriteHeader(403)
63+
return
64+
5665
case "/not_found":
5766
}
5867

0 commit comments

Comments
 (0)