version_upgrade_test.go 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
Copyright 2019 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integration

import (
	"io"
	"io/ioutil"
	"net/http"
	"os"
	"runtime"
	"testing"

	"github.com/docker/machine/libmachine/state"
	"github.com/pkg/errors"
S
Sharif Elgamal 已提交
29
	pkgutil "k8s.io/minikube/pkg/util"
30 31 32 33 34 35 36 37 38
	"k8s.io/minikube/test/integration/util"
)

func TestVersionUpgrade(t *testing.T) {
	currentRunner := NewMinikubeRunner(t)
	currentRunner.RunCommand("delete", true)
	currentRunner.CheckStatus(state.None.String())

	// Grab latest release binary
S
Sharif Elgamal 已提交
39
	url := pkgutil.GetBinaryDownloadURL("latest", runtime.GOOS)
40 41 42 43 44 45
	resp, err := http.Get(url)
	if err != nil {
		t.Fatal(errors.Wrap(err, "Failed to get latest release binary"))
	}
	defer resp.Body.Close()

S
Sharif Elgamal 已提交
46
	tf, err := ioutil.TempFile("", "minikube")
47 48 49
	if err != nil {
		t.Fatal(errors.Wrap(err, "Failed to create binary file"))
	}
S
Sharif Elgamal 已提交
50
	defer os.Remove(tf.Name())
51

S
Sharif Elgamal 已提交
52
	_, err = io.Copy(tf, resp.Body)
53
	if err != nil {
S
Sharif Elgamal 已提交
54
		t.Fatal(errors.Wrap(err, "Failed to populate temp file"))
55
	}
S
Sharif Elgamal 已提交
56 57
	if err := tf.Close(); err != nil {
		t.Fatal(errors.Wrap(err, "Failed to close temp file"))
58 59 60
	}

	if runtime.GOOS != "windows" {
S
Sharif Elgamal 已提交
61
		if err := os.Chmod(tf.Name(), 0700); err != nil {
62 63 64 65
			t.Fatal(errors.Wrap(err, "Failed to make binary executable."))
		}
	}

S
Sharif Elgamal 已提交
66
	releaseRunner := util.MinikubeRunner{
67
		Args:       currentRunner.Args,
S
Sharif Elgamal 已提交
68
		BinaryPath: tf.Name(),
69 70 71 72
		StartArgs:  currentRunner.StartArgs,
		MountArgs:  currentRunner.MountArgs,
		T:          t,
	}
S
Sharif Elgamal 已提交
73 74 75 76
	releaseRunner.Start()
	releaseRunner.CheckStatus(state.Running.String())
	releaseRunner.RunCommand("stop", true)
	releaseRunner.CheckStatus(state.Stopped.String())
77 78 79 80 81 82

	currentRunner.Start()
	currentRunner.CheckStatus(state.Running.String())
	currentRunner.RunCommand("delete", true)
	currentRunner.CheckStatus(state.None.String())
}