mirror of
https://github.com/mudler/LocalAI.git
synced 2025-06-29 14:14:59 +00:00
test(resume downloads): implement file download tc
Signed-off-by: Saarthak Verma <saarthakverma739@gmail.com>
This commit is contained in:
parent
d7e88754d4
commit
9e555bb187
1 changed files with 34 additions and 3 deletions
|
@ -1,6 +1,13 @@
|
|||
package downloader_test
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
|
||||
. "github.com/mudler/LocalAI/pkg/downloader"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
@ -40,8 +47,32 @@ var _ = Describe("Gallery API tests", func() {
|
|||
})
|
||||
|
||||
var _ = Describe("Download Test", func() {
|
||||
Context("URI", func() {
|
||||
It("Resumes partially downloaded files")
|
||||
It("It accurately updates progress")
|
||||
Context("URI DownloadFile", func() {
|
||||
It("fetches files from mock server", func() {
|
||||
mockData := make([]byte, 20000)
|
||||
_, err := rand.Read(mockData)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
mockDataSha := sha256.New()
|
||||
mockDataSha.Write(mockData)
|
||||
|
||||
mockServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(mockData)
|
||||
}))
|
||||
mockServer.EnableHTTP2 = true
|
||||
mockServer.Start()
|
||||
dir, err := os.Getwd()
|
||||
filePath := dir + "/my_supercool_model"
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
uri := URI(mockServer.URL)
|
||||
err = uri.DownloadFile(filePath, fmt.Sprintf("%x", mockDataSha.Sum(nil)), 1, 1, func(s1, s2, s3 string, f float64) {})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = os.Remove(filePath) // cleanup, also checks existance of filePath`
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
// It("resumes partially downloaded files")
|
||||
// It("it accurately updates progress")
|
||||
// It("deletes partial file if after completion hash of downloaded file doesn't match hash of the file in the server")
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue