diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-09-23 12:50:59 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-09-23 15:29:18 +0200 |
commit | a5e662b6cf9ada7c4371c92405fe3de6866d7b0a (patch) | |
tree | 24e44df4ab5f8ff9e1f6ccab0769c4fdc6babb7f /updater/winhttp/winhttp_test.go | |
parent | embeddable-dll-service: add basic outline for embedding wireguard (diff) | |
download | wireguard-windows-a5e662b6cf9ada7c4371c92405fe3de6866d7b0a.tar.xz wireguard-windows-a5e662b6cf9ada7c4371c92405fe3de6866d7b0a.zip |
updater: use winhttp to reduce filesize
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'updater/winhttp/winhttp_test.go')
-rw-r--r-- | updater/winhttp/winhttp_test.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/updater/winhttp/winhttp_test.go b/updater/winhttp/winhttp_test.go new file mode 100644 index 00000000..42f38caa --- /dev/null +++ b/updater/winhttp/winhttp_test.go @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +package winhttp + +import ( + "fmt" + "io" + "io/ioutil" + "testing" +) + +type progressPrinter struct { + downloaded uint64 + total uint64 +} + +func (pp *progressPrinter) Write(p []byte) (int, error) { + bytes := len(p) + pp.downloaded += uint64(bytes) + fmt.Printf("%d/%d bytes, %f%%\n", pp.downloaded, pp.total, float64(pp.downloaded)/float64(pp.total)*100.0) + return bytes, nil +} + +func TestResponse(t *testing.T) { + r, err := Get("WinHTTP Test Suite/1.0", "https://www.zx2c4.com/ip") + if err != nil { + t.Fatal(err) + } + length, err := r.Length() + if err != nil { + t.Fatal(err) + } + fmt.Printf("The length is %d\n", length) + bytes, err := ioutil.ReadAll(r) + if err != nil { + t.Fatal(err) + } + fmt.Println(string(bytes)) + r.Close() + + r, err = Get("WinHTTP Test Suite/1.0", "https://speed.hetzner.de/10GB.bin") + if err != nil { + t.Fatal(err) + } + length, err = r.Length() + if err != nil { + t.Fatal(err) + } + _, err = io.Copy(&progressPrinter{total: length}, r) + if err != nil { + t.Fatal(err) + } + r.Close() +} |