github.com/upyun/upx@v0.4.7-0.20240419023638-b184a7cb7c10/partial/downloader_test.go (about)

     1  package partial
     2  
     3  import (
     4  	"bytes"
     5  	"crypto/md5"
     6  	"strings"
     7  	"testing"
     8  )
     9  
    10  func TestDownload(t *testing.T) {
    11  	var buffer bytes.Buffer
    12  
    13  	filedata := []byte(strings.Repeat("hello world", 1024*100))
    14  	download := NewMultiPartialDownloader(
    15  		"myTestfile",
    16  		int64(len(filedata)),
    17  		1024,
    18  		&buffer,
    19  		3,
    20  		func(start, end int64) ([]byte, error) {
    21  			return filedata[start : end+1], nil
    22  		},
    23  	)
    24  
    25  	err := download.Download()
    26  	if err != nil {
    27  		t.Fatal(err.Error())
    28  	}
    29  	if md5.Sum(buffer.Bytes()) != md5.Sum(filedata) {
    30  		t.Fatal("download file has diff MD5")
    31  	}
    32  }