Gestion err download
This commit is contained in:
parent
c1134f7403
commit
80ef56bbc4
@ -1,7 +1,6 @@
|
||||
package tool
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@ -55,14 +54,18 @@ EOF
|
||||
|
||||
version, err1 := install.Version(dest)
|
||||
assert.Equal(t, "v1.30.3", version, "TestToolKubectl error")
|
||||
|
||||
fmt.Println(" err1 ", err1)
|
||||
|
||||
assert.Nilf(t, err1, "TestToolKubectl error")
|
||||
}
|
||||
|
||||
|
||||
func TestToolKubectlErr(t *testing.T) {
|
||||
|
||||
httpmock.Activate()
|
||||
defer httpmock.DeactivateAndReset()
|
||||
|
||||
httpmock.RegisterResponder("GET", "http://test/1.0",
|
||||
httpmock.NewStringResponder(404, ""))
|
||||
|
||||
data := ToolData{Bin: TEST_DEST_DIR,
|
||||
Name: "test",
|
||||
Version: "1.0",
|
||||
@ -75,5 +78,5 @@ func TestToolKubectlErr(t *testing.T) {
|
||||
|
||||
err := install.Download()
|
||||
|
||||
assert.NotNilf(t, err, "error message %s", "Download")
|
||||
assert.NotNilf(t, err, "error message %s", err)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"io"
|
||||
"path"
|
||||
@ -16,6 +17,10 @@ func DownloadFromUrl(dest string, url string, chmod os.FileMode) error {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode > 400 {
|
||||
txt, _ := io.ReadAll(resp.Body)
|
||||
return fmt.Errorf(string(txt))
|
||||
}
|
||||
|
||||
out, err := os.Create(dest)
|
||||
defer out.Close()
|
||||
|
Loading…
Reference in New Issue
Block a user