adding retriable http get

pull/4474/head
Medya Gh 2019-06-12 10:44:04 -07:00
parent eb96756744
commit d3855d4b09
3 changed files with 32 additions and 15 deletions

1
go.mod
View File

@ -31,6 +31,7 @@ require (
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce // indirect
github.com/hashicorp/go-multierror v0.0.0-20160811015721-8c5f0ad93604 // indirect
github.com/hashicorp/go-retryablehttp v0.5.4
github.com/hashicorp/go-version v1.1.0 // indirect
github.com/hashicorp/golang-lru v0.0.0-20160207214719-a0d98a5f2880 // indirect
github.com/hashicorp/hcl v0.0.0-20160711231752-d8c773c4cba1 // indirect

4
go.sum
View File

@ -64,8 +64,12 @@ github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWet
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce h1:prjrVgOk2Yg6w+PflHoszQNLTUh4kaByUcEWM/9uin4=
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-multierror v0.0.0-20160811015721-8c5f0ad93604 h1:VIq8E7fMiC4h3agg0ya56L0jHn7QisZZcWZXVKJb9jQ=
github.com/hashicorp/go-multierror v0.0.0-20160811015721-8c5f0ad93604/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I=
github.com/hashicorp/go-retryablehttp v0.5.4 h1:1BZvpawXoJCWX6pNtow9+rpEj+3itIlutiqnntI6jOE=
github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.0.0-20160207214719-a0d98a5f2880 h1:OaRuzt9oCKNui8cCskZijoKUwe+aCuuCwvx1ox8FNyw=

View File

@ -20,49 +20,61 @@ import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"runtime"
"testing"
"github.com/docker/machine/libmachine/state"
retryablehttp "github.com/hashicorp/go-retryablehttp"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/constants"
pkgutil "k8s.io/minikube/pkg/util"
)
func TestVersionUpgrade(t *testing.T) {
currentRunner := NewMinikubeRunner(t)
currentRunner.RunCommand("delete", true)
currentRunner.CheckStatus(state.None.String())
func downloadMinikubeBinary(version string) (*os.File, error) {
// Grab latest release binary
url := pkgutil.GetBinaryDownloadURL("latest", runtime.GOOS)
resp, err := http.Get(url)
url := pkgutil.GetBinaryDownloadURL(version, runtime.GOOS)
resp, err := retryablehttp.Get(url)
if err != nil {
t.Fatal(errors.Wrap(err, "Failed to get latest release binary"))
return nil, err
// t.Fatal(errors.Wrap(err, "Failed to get latest release binary"))
}
defer resp.Body.Close()
tf, err := ioutil.TempFile("", "minikube")
if err != nil {
t.Fatal(errors.Wrap(err, "Failed to create binary file"))
return nil, err
// t.Fatal(errors.Wrap(err, "Failed to create binary file"))
}
defer os.Remove(tf.Name())
_, err = io.Copy(tf, resp.Body)
if err != nil {
t.Fatal(errors.Wrap(err, "Failed to populate temp file"))
return nil, err
// t.Fatal(errors.Wrap(err, "Failed to populate temp file"))
}
if err := tf.Close(); err != nil {
t.Fatal(errors.Wrap(err, "Failed to close temp file"))
return nil, err
// t.Fatal(errors.Wrap(err, "Failed to close temp file"))
}
if runtime.GOOS != "windows" {
if err := os.Chmod(tf.Name(), 0700); err != nil {
t.Fatal(errors.Wrap(err, "Failed to make binary executable."))
return nil, err
// t.Fatal(errors.Wrap(err, "Failed to make binary executable."))
}
}
return tf, err
}
// TestVersionUpgrade downloads latest version of minikube and runs with
// the odlest supported k8s version and then runs the current head minikube
// and it tries to upgrade from the older supported k8s to news supported k8s
func TestVersionUpgrade(t *testing.T) {
currentRunner := NewMinikubeRunner(t)
currentRunner.RunCommand("delete", true)
currentRunner.CheckStatus(state.None.String())
tf, err := downloadMinikubeBinary("latest")
t.Fatal(errors.Wrap(err, "Failed to download minikube binary."))
defer os.Remove(tf.Name())
releaseRunner := NewMinikubeRunner(t)
releaseRunner.BinaryPath = tf.Name()