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