2024-09-02 11:44:44 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
// https://pkg.go.dev/github.com/stretchr/testify/assert#Nilf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/jarcoal/httpmock"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDownload(t *testing.T){
|
|
|
|
httpmock.Activate()
|
|
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
|
|
|
|
url := "http://test.download.com"
|
|
|
|
|
|
|
|
httpmock.RegisterResponder("GET", url,
|
|
|
|
httpmock.NewStringResponder(200, `CONTENU_URL`))
|
|
|
|
|
|
|
|
dest := filepath.Join(TEST_DEST_DIR, "url")
|
|
|
|
|
|
|
|
err := DownloadFromUrl(dest, url, 777)
|
|
|
|
assert.Nilf(t, err, "error message %s", url)
|
|
|
|
assert.FileExists(t, dest, "DownloadFromUrl error")
|
|
|
|
}
|