Merge pull request #3187 from tstromberg/consistent_err_formatting

Globally replace %s format directives with %v for error strings
pull/3268/head
Thomas Strömberg 2018-10-19 16:44:46 -07:00 committed by GitHub
commit 2621bb3a27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
57 changed files with 133 additions and 132 deletions

View File

@ -18,12 +18,13 @@ package cmd
import ( import (
"fmt" "fmt"
"os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
cmdConfig "k8s.io/minikube/cmd/minikube/cmd/config" cmdConfig "k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/machine" "k8s.io/minikube/pkg/minikube/machine"
"os"
) )
// cacheCmd represents the cache command // cacheCmd represents the cache command
@ -41,12 +42,12 @@ var addCacheCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// Cache and load images into docker daemon // Cache and load images into docker daemon
if err := machine.CacheAndLoadImages(args); err != nil { if err := machine.CacheAndLoadImages(args); err != nil {
fmt.Fprintf(os.Stderr, "Error caching and loading images: %s\n", err) fmt.Fprintf(os.Stderr, "Error caching and loading images: %v\n", err)
os.Exit(1) os.Exit(1)
} }
// Add images to config file // Add images to config file
if err := cmdConfig.AddToConfigMap(constants.Cache, args); err != nil { if err := cmdConfig.AddToConfigMap(constants.Cache, args); err != nil {
fmt.Fprintf(os.Stderr, "Error adding cached images to config file: %s\n", err) fmt.Fprintf(os.Stderr, "Error adding cached images to config file: %v\n", err)
os.Exit(1) os.Exit(1)
} }
}, },
@ -60,12 +61,12 @@ var deleteCacheCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// Delete images from config file // Delete images from config file
if err := cmdConfig.DeleteFromConfigMap(constants.Cache, args); err != nil { if err := cmdConfig.DeleteFromConfigMap(constants.Cache, args); err != nil {
fmt.Fprintf(os.Stderr, "Error deleting images from config file: %s\n", err) fmt.Fprintf(os.Stderr, "Error deleting images from config file: %v\n", err)
os.Exit(1) os.Exit(1)
} }
// Delete images from cache/images directory // Delete images from cache/images directory
if err := machine.DeleteFromImageCacheDir(args); err != nil { if err := machine.DeleteFromImageCacheDir(args); err != nil {
fmt.Fprintf(os.Stderr, "Error deleting images: %s\n", err) fmt.Fprintf(os.Stderr, "Error deleting images: %v\n", err)
os.Exit(1) os.Exit(1)
} }
}, },

View File

@ -41,11 +41,11 @@ var listCacheCmd = &cobra.Command{
// list images from config file // list images from config file
images, err := cmdConfig.ListConfigMap(constants.Cache) images, err := cmdConfig.ListConfigMap(constants.Cache)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error listing image entries from config: %s\n", err) fmt.Fprintf(os.Stderr, "Error listing image entries from config: %v\n", err)
os.Exit(1) os.Exit(1)
} }
if err := cacheList(images); err != nil { if err := cacheList(images); err != nil {
fmt.Fprintf(os.Stderr, "Error listing images: %s\n", err) fmt.Fprintf(os.Stderr, "Error listing images: %v\n", err)
os.Exit(1) os.Exit(1)
} }
}, },
@ -62,13 +62,13 @@ func cacheList(images []string) error {
for _, image := range images { for _, image := range images {
tmpl, err := template.New("list").Parse(cacheListFormat) tmpl, err := template.New("list").Parse(cacheListFormat)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error creating list template: %s\n", err) fmt.Fprintf(os.Stderr, "Error creating list template: %v\n", err)
os.Exit(1) os.Exit(1)
} }
listTmplt := CacheListTemplate{image} listTmplt := CacheListTemplate{image}
err = tmpl.Execute(os.Stdout, listTmplt) err = tmpl.Execute(os.Stdout, listTmplt)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error executing list template: %s\n", err) fmt.Fprintf(os.Stderr, "Error executing list template: %v\n", err)
os.Exit(1) os.Exit(1)
} }
} }

View File

@ -80,7 +80,7 @@ func TestHiddenPrint(t *testing.T) {
} }
result, err := concealableAskForStaticValue(b, "hello", false) result, err := concealableAskForStaticValue(b, "hello", false)
if err != nil && !test.ShouldError { if err != nil && !test.ShouldError {
t.Errorf("Error asking for concealable static value: %s", err) t.Errorf("Error asking for concealable static value: %v", err)
continue continue
} }
if result != test.TestString { if result != test.TestString {
@ -94,7 +94,7 @@ func TestWriteConfig(t *testing.T) {
for _, tt := range configTestCases { for _, tt := range configTestCases {
err := encode(&b, tt.config) err := encode(&b, tt.config)
if err != nil { if err != nil {
t.Errorf("Error encoding: %s", err) t.Errorf("Error encoding: %v", err)
} }
if b.String() != tt.data { if b.String() != tt.data {
t.Errorf("Did not write config correctly, \n\n expected:\n %+v \n\n actual:\n %+v", tt.data, b.String()) t.Errorf("Did not write config correctly, \n\n expected:\n %+v \n\n actual:\n %+v", tt.data, b.String())

View File

@ -61,7 +61,7 @@ var addonsOpenCmd = &cobra.Command{
//TODO(r2d4): config should not reference API, pull this out //TODO(r2d4): config should not reference API, pull this out
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()
@ -91,7 +91,7 @@ minikube addons enable %s`, addonName, addonName))
serviceList, err := service.GetServiceListByLabel(namespace, key, addonName) serviceList, err := service.GetServiceListByLabel(namespace, key, addonName)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting service with namespace: %s and labels %s:%s: %s\n", namespace, key, addonName, err) fmt.Fprintf(os.Stderr, "Error getting service with namespace: %s and labels %s:%s: %v\n", namespace, key, addonName, err)
os.Exit(1) os.Exit(1)
} }
if len(serviceList.Items) == 0 { if len(serviceList.Items) == 0 {

View File

@ -104,7 +104,7 @@ func EnableOrDisableAddon(name string, val string) error {
//TODO(r2d4): config package should not reference API, pull this out //TODO(r2d4): config package should not reference API, pull this out
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()

View File

@ -38,7 +38,7 @@ func TestFindSettingNotFound(t *testing.T) {
func TestFindSetting(t *testing.T) { func TestFindSetting(t *testing.T) {
s, err := findSetting("vm-driver") s, err := findSetting("vm-driver")
if err != nil { if err != nil {
t.Fatalf("Couldn't find setting, vm-driver: %s", err) t.Fatalf("Couldn't find setting, vm-driver: %v", err)
} }
if s.name != "vm-driver" { if s.name != "vm-driver" {
t.Fatalf("Found wrong setting, expected vm-driver, got %s", s.name) t.Fatalf("Found wrong setting, expected vm-driver, got %s", s.name)
@ -48,14 +48,14 @@ func TestFindSetting(t *testing.T) {
func TestSetString(t *testing.T) { func TestSetString(t *testing.T) {
err := SetString(minikubeConfig, "vm-driver", "virtualbox") err := SetString(minikubeConfig, "vm-driver", "virtualbox")
if err != nil { if err != nil {
t.Fatalf("Couldnt set string: %s", err) t.Fatalf("Couldnt set string: %v", err)
} }
} }
func TestSetInt(t *testing.T) { func TestSetInt(t *testing.T) {
err := SetInt(minikubeConfig, "cpus", "22") err := SetInt(minikubeConfig, "cpus", "22")
if err != nil { if err != nil {
t.Fatalf("Couldn't set int in config: %s", err) t.Fatalf("Couldn't set int in config: %v", err)
} }
val, ok := minikubeConfig["cpus"].(int) val, ok := minikubeConfig["cpus"].(int)
if !ok { if !ok {
@ -69,7 +69,7 @@ func TestSetInt(t *testing.T) {
func TestSetBool(t *testing.T) { func TestSetBool(t *testing.T) {
err := SetBool(minikubeConfig, "show-libmachine-logs", "true") err := SetBool(minikubeConfig, "show-libmachine-logs", "true")
if err != nil { if err != nil {
t.Fatalf("Couldn't set bool in config: %s", err) t.Fatalf("Couldn't set bool in config: %v", err)
} }
val, ok := minikubeConfig["show-libmachine-logs"].(bool) val, ok := minikubeConfig["show-libmachine-logs"].(bool)
if !ok { if !ok {

View File

@ -59,7 +59,7 @@ var dashboardCmd = &cobra.Command{
}() }()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error creating client: %v\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
cluster.EnsureMinikubeRunningOrExit(api, 1) cluster.EnsureMinikubeRunningOrExit(api, 1)

View File

@ -44,7 +44,7 @@ associated files.`,
fmt.Println("Deleting local Kubernetes cluster...") fmt.Println("Deleting local Kubernetes cluster...")
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()

View File

@ -302,13 +302,13 @@ var dockerEnvCmd = &cobra.Command{
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()
host, err := cluster.CheckIfHostExistsAndLoad(api, config.GetMachineName()) host, err := cluster.CheckIfHostExistsAndLoad(api, config.GetMachineName())
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting host: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting host: %v\n", err)
os.Exit(1) os.Exit(1)
} }
if host.Driver.DriverName() == "none" { if host.Driver.DriverName() == "none" {

View File

@ -248,7 +248,7 @@ func TestShellCfgSet(t *testing.T) {
t.Errorf("Shell cfgs differ: expected %+v, \n\n got %+v", test.expectedShellCfg, shellCfg) t.Errorf("Shell cfgs differ: expected %+v, \n\n got %+v", test.expectedShellCfg, shellCfg)
} }
if err != nil && !test.shouldErr { if err != nil && !test.shouldErr {
t.Errorf("Test should have failed but didn't return error: %s, error: %s", test.description, err) t.Errorf("Test should have failed but didn't return error: %s, error: %v", test.description, err)
} }
if err == nil && test.shouldErr { if err == nil && test.shouldErr {
t.Errorf("Test didn't return error but should have: %s", test.description) t.Errorf("Test didn't return error but should have: %s", test.description)

View File

@ -34,7 +34,7 @@ var ipCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()

View File

@ -41,13 +41,13 @@ var logsCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()
clusterBootstrapper, err := GetClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper)) clusterBootstrapper, err := GetClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper))
if err != nil { if err != nil {
glog.Exitf("Error getting cluster bootstrapper: %s", err) glog.Exitf("Error getting cluster bootstrapper: %v", err)
} }
err = clusterBootstrapper.GetClusterLogsTo(follow, os.Stdout) err = clusterBootstrapper.GetClusterLogsTo(follow, os.Stdout)

View File

@ -93,7 +93,7 @@ var mountCmd = &cobra.Command{
} }
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()

View File

@ -70,7 +70,7 @@ var RootCmd = &cobra.Command{
PersistentPreRun: func(cmd *cobra.Command, args []string) { PersistentPreRun: func(cmd *cobra.Command, args []string) {
for _, path := range dirs { for _, path := range dirs {
if err := os.MkdirAll(path, 0777); err != nil { if err := os.MkdirAll(path, 0777); err != nil {
glog.Exitf("Error creating minikube directory: %s", err) glog.Exitf("Error creating minikube directory: %v", err)
} }
} }
@ -143,7 +143,7 @@ func initConfig() {
viper.SetConfigType("json") viper.SetConfigType("json")
err := viper.ReadInConfig() err := viper.ReadInConfig()
if err != nil { if err != nil {
glog.Warningf("Error reading config file at %s: %s", configPath, err) glog.Warningf("Error reading config file at %s: %v", configPath, err)
} }
setupViper() setupViper()
} }

View File

@ -65,7 +65,7 @@ var serviceCmd = &cobra.Command{
svc := args[0] svc := args[0]
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()
@ -74,7 +74,7 @@ var serviceCmd = &cobra.Command{
err = service.WaitAndMaybeOpenService(api, namespace, svc, err = service.WaitAndMaybeOpenService(api, namespace, svc,
serviceURLTemplate, serviceURLMode, https, wait, interval) serviceURLTemplate, serviceURLMode, https, wait, interval)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error opening service: %s\n", err) fmt.Fprintf(os.Stderr, "Error opening service: %v\n", err)
os.Exit(1) os.Exit(1)
} }
}, },

View File

@ -39,7 +39,7 @@ var serviceListCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()

View File

@ -36,13 +36,13 @@ var sshCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()
host, err := cluster.CheckIfHostExistsAndLoad(api, config.GetMachineName()) host, err := cluster.CheckIfHostExistsAndLoad(api, config.GetMachineName())
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting host: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting host: %v\n", err)
os.Exit(1) os.Exit(1)
} }
if host.Driver.DriverName() == "none" { if host.Driver.DriverName() == "none" {

View File

@ -112,14 +112,14 @@ func runStart(cmd *cobra.Command, args []string) {
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()
exists, err := api.Exists(cfg.GetMachineName()) exists, err := api.Exists(cfg.GetMachineName())
if err != nil { if err != nil {
glog.Exitf("checking if machine exists: %s", err) glog.Exitf("checking if machine exists: %v", err)
} }
diskSize := viper.GetString(humanReadableDiskSize) diskSize := viper.GetString(humanReadableDiskSize)
@ -165,7 +165,7 @@ func runStart(cmd *cobra.Command, args []string) {
start := func() (err error) { start := func() (err error) {
host, err = cluster.StartHost(api, config) host, err = cluster.StartHost(api, config)
if err != nil { if err != nil {
glog.Errorf("Error starting host: %s.\n\n Retrying.\n", err) glog.Errorf("Error starting host: %v.\n\n Retrying.\n", err)
} }
return err return err
} }
@ -228,7 +228,7 @@ func runStart(cmd *cobra.Command, args []string) {
k8sBootstrapper, err := GetClusterBootstrapper(api, clusterBootstrapper) k8sBootstrapper, err := GetClusterBootstrapper(api, clusterBootstrapper)
if err != nil { if err != nil {
glog.Exitf("Error getting cluster bootstrapper: %s", err) glog.Exitf("Error getting cluster bootstrapper: %v", err)
} }
// Write profile cluster configuration to file // Write profile cluster configuration to file
@ -321,12 +321,12 @@ func runStart(cmd *cobra.Command, args []string) {
} }
err = mountCmd.Start() err = mountCmd.Start()
if err != nil { if err != nil {
glog.Errorf("Error running command minikube mount %s", err) glog.Errorf("Error running command minikube mount %v", err)
cmdutil.MaybeReportErrorAndExit(err) cmdutil.MaybeReportErrorAndExit(err)
} }
err = ioutil.WriteFile(filepath.Join(constants.GetMinipath(), constants.MountProcessFileName), []byte(strconv.Itoa(mountCmd.Process.Pid)), 0644) err = ioutil.WriteFile(filepath.Join(constants.GetMinipath(), constants.MountProcessFileName), []byte(strconv.Itoa(mountCmd.Process.Pid)), 0644)
if err != nil { if err != nil {
glog.Errorf("Error writing mount process pid to file: %s", err) glog.Errorf("Error writing mount process pid to file: %v", err)
cmdutil.MaybeReportErrorAndExit(err) cmdutil.MaybeReportErrorAndExit(err)
} }
} }

View File

@ -61,7 +61,7 @@ var statusCmd = &cobra.Command{
var returnCode = 0 var returnCode = 0
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(internalErrorCode) os.Exit(internalErrorCode)
} }
defer api.Close() defer api.Close()
@ -77,7 +77,7 @@ var statusCmd = &cobra.Command{
if ms == state.Running.String() { if ms == state.Running.String() {
clusterBootstrapper, err := GetClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper)) clusterBootstrapper, err := GetClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper))
if err != nil { if err != nil {
glog.Errorf("Error getting cluster bootstrapper: %s", err) glog.Errorf("Error getting cluster bootstrapper: %v", err)
cmdUtil.MaybeReportErrorAndExitWithCode(err, internalErrorCode) cmdUtil.MaybeReportErrorAndExitWithCode(err, internalErrorCode)
} }
cs, err = clusterBootstrapper.GetClusterStatus() cs, err = clusterBootstrapper.GetClusterStatus()

View File

@ -36,7 +36,7 @@ itself, leaving all files intact. The cluster can be started again with the "sta
fmt.Println("Stopping local Kubernetes cluster...") fmt.Println("Stopping local Kubernetes cluster...")
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()

View File

@ -39,7 +39,7 @@ var updateContextCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
api, err := machine.NewAPIClient() api, err := machine.NewAPIClient()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1) os.Exit(1)
} }
defer api.Close() defer api.Close()

View File

@ -28,7 +28,7 @@ import (
func main() { func main() {
// Glog requires that /tmp exists. // Glog requires that /tmp exists.
if err := os.MkdirAll("/tmp", 0755); err != nil { if err := os.MkdirAll("/tmp", 0755); err != nil {
fmt.Printf("Error creating tmpdir: %s\n", err) fmt.Printf("Error creating tmpdir: %v\n", err)
os.Exit(1) os.Exit(1)
} }
flag.Parse() flag.Parse()

View File

@ -48,7 +48,7 @@ func TestFormatError(t *testing.T) {
_, err := FormatError(testErr) _, err := FormatError(testErr)
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %s", err) t.Fatalf("Unexpected error: %v", err)
} }
} }
@ -59,7 +59,7 @@ func TestMarshallError(t *testing.T) {
errMsg, _ := FormatError(testErr) errMsg, _ := FormatError(testErr)
if _, err := MarshallError(errMsg, "default", version.GetVersion()); err != nil { if _, err := MarshallError(errMsg, "default", version.GetVersion()); err != nil {
t.Fatalf("Unexpected error: %s", err) t.Fatalf("Unexpected error: %v", err)
} }
} }
@ -75,7 +75,7 @@ func TestUploadError(t *testing.T) {
})) }))
if err := UploadError(jsonErrMsg, server.URL); err != nil { if err := UploadError(jsonErrMsg, server.URL); err != nil {
t.Fatalf("Unexpected error: %s", err) t.Fatalf("Unexpected error: %v", err)
} }
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

View File

@ -50,7 +50,7 @@ func getShaFromURL(url string) (string, error) {
func TestReleasesJson(t *testing.T) { func TestReleasesJson(t *testing.T) {
releases, err := notify.GetAllVersionsFromURL(constants.GithubMinikubeReleasesURL) releases, err := notify.GetAllVersionsFromURL(constants.GithubMinikubeReleasesURL)
if err != nil { if err != nil {
t.Fatalf("Error getting releases.json: %s", err) t.Fatalf("Error getting releases.json: %v", err)
} }
for _, r := range releases { for _, r := range releases {
@ -59,7 +59,7 @@ func TestReleasesJson(t *testing.T) {
fmt.Printf("Checking SHA for %s.\n", platform) fmt.Printf("Checking SHA for %s.\n", platform)
actualSha, err := getShaFromURL(util.GetBinaryDownloadURL(r.Name, platform)) actualSha, err := getShaFromURL(util.GetBinaryDownloadURL(r.Name, platform))
if err != nil { if err != nil {
t.Errorf("Error calculating SHA for %s-%s. Error: %s", r.Name, platform, err) t.Errorf("Error calculating SHA for %s-%s. Error: %v", r.Name, platform, err)
continue continue
} }
if actualSha != sha { if actualSha != sha {

View File

@ -151,7 +151,7 @@ func (d *Driver) Kill() error {
func (d *Driver) Remove() error { func (d *Driver) Remove() error {
s, err := d.GetState() s, err := d.GetState()
if err != nil || s == state.Error { if err != nil || s == state.Error {
log.Infof("Error checking machine status: %s, assuming it has been removed already", err) log.Infof("Error checking machine status: %v, assuming it has been removed already", err)
} }
if s == state.Running { if s == state.Running {
if err := d.Stop(); err != nil { if err := d.Stop(); err != nil {
@ -229,7 +229,8 @@ func (d *Driver) Start() error {
time.Sleep(time.Second * 30) time.Sleep(time.Second * 30)
err = d.setupNFSShare() err = d.setupNFSShare()
if err != nil { if err != nil {
log.Errorf("NFS setup failed: %s", err.Error()) // TODO(tstromberg): Check that logging an and error and return it is appropriate. Seems weird.
log.Errorf("NFS setup failed: %v", err)
return err return err
} }
} }
@ -350,13 +351,13 @@ func (d *Driver) getPid() int {
f, err := os.Open(pidPath) f, err := os.Open(pidPath)
if err != nil { if err != nil {
log.Warnf("Error reading pid file: %s", err) log.Warnf("Error reading pid file: %v", err)
return 0 return 0
} }
dec := json.NewDecoder(f) dec := json.NewDecoder(f)
config := hyperkit.HyperKit{} config := hyperkit.HyperKit{}
if err := dec.Decode(&config); err != nil { if err := dec.Decode(&config); err != nil {
log.Warnf("Error decoding pid file: %s", err) log.Warnf("Error decoding pid file: %v", err)
return 0 return 0
} }
@ -368,12 +369,12 @@ func (d *Driver) cleanupNfsExports() {
log.Infof("You must be root to remove NFS shared folders. Please type root password.") log.Infof("You must be root to remove NFS shared folders. Please type root password.")
for _, share := range d.NFSShares { for _, share := range d.NFSShares {
if _, err := nfsexports.Remove("", d.nfsExportIdentifier(share)); err != nil { if _, err := nfsexports.Remove("", d.nfsExportIdentifier(share)); err != nil {
log.Errorf("failed removing nfs share (%s): %s", share, err.Error()) log.Errorf("failed removing nfs share (%s): %v", share, err)
} }
} }
if err := nfsexports.ReloadDaemon(); err != nil { if err := nfsexports.ReloadDaemon(); err != nil {
log.Errorf("failed to reload the nfs daemon: %s", err.Error()) log.Errorf("failed to reload the nfs daemon: %v", err)
} }
} }
} }

View File

@ -370,7 +370,7 @@ func (d *Driver) Remove() error {
// Tear down network if it exists and is not in use by another minikube instance // Tear down network if it exists and is not in use by another minikube instance
log.Debug("Trying to delete the networks (if possible)") log.Debug("Trying to delete the networks (if possible)")
if err := d.deleteNetwork(); err != nil { if err := d.deleteNetwork(); err != nil {
log.Warnf("Deleting of networks failed: %s", err.Error()) log.Warnf("Deleting of networks failed: %v", err)
} else { } else {
log.Info("Successfully deleted networks") log.Info("Successfully deleted networks")
} }

View File

@ -277,7 +277,7 @@ func (d *Driver) lookupIPFromStatusFile(conn *libvirt.Connect) (string, error) {
bridge, err := network.GetBridgeName() bridge, err := network.GetBridgeName()
if err != nil { if err != nil {
log.Warnf("Failed to get network bridge: %s", err) log.Warnf("Failed to get network bridge: %v", err)
return "", err return "", err
} }
statusFile := fmt.Sprintf("/var/lib/libvirt/dnsmasq/%s.status", bridge) statusFile := fmt.Sprintf("/var/lib/libvirt/dnsmasq/%s.status", bridge)

View File

@ -124,7 +124,7 @@ func (d *Driver) Kill() error {
} { } {
cmd := exec.Command("sudo", cmdStr...) cmd := exec.Command("sudo", cmdStr...)
if out, err := cmd.CombinedOutput(); err != nil { if out, err := cmd.CombinedOutput(); err != nil {
glog.Warningf("Error %s running command: %s. Output: %s", err, cmdStr, string(out)) glog.Warningf("Error %v running command: %s. Output: %s", err, cmdStr, out)
} }
} }
return nil return nil
@ -138,7 +138,7 @@ func (d *Driver) Remove() error {
for _, cmdStr := range []string{rmCmd, dockerkillcmd} { for _, cmdStr := range []string{rmCmd, dockerkillcmd} {
if out, err := runCommand(cmdStr, true); err != nil { if out, err := runCommand(cmdStr, true); err != nil {
glog.Warningf("Error %s running command: %s, Output: %s", err, cmdStr, out) glog.Warningf("Error %v running command: %s, Output: %s", err, cmdStr, out)
} }
} }
@ -192,7 +192,7 @@ fi
} }
} }
if out, err := runCommand(dockerstopcmd, false); err != nil { if out, err := runCommand(dockerstopcmd, false); err != nil {
glog.Warningf("Error %s running command %s. Output: %s", err, dockerstopcmd, out) glog.Warningf("Error %v running command %s. Output: %s", err, dockerstopcmd, out)
} }
return nil return nil
} }

View File

@ -44,7 +44,7 @@ func TestSetupCerts(t *testing.T) {
} }
if err := SetupCerts(f, k8s); err != nil { if err := SetupCerts(f, k8s); err != nil {
t.Fatalf("Error starting cluster: %s", err) t.Fatalf("Error starting cluster: %v", err)
} }
for _, cert := range filesToBeTransferred { for _, cert := range filesToBeTransferred {
_, err := f.GetFileToContents(cert) _, err := f.GetFileToContents(cert)

View File

@ -234,7 +234,7 @@ schedulerExtraArgs:
t.Run(test.description, func(t *testing.T) { t.Run(test.description, func(t *testing.T) {
actualCfg, err := generateConfig(test.cfg) actualCfg, err := generateConfig(test.cfg)
if err != nil && !test.shouldErr { if err != nil && !test.shouldErr {
t.Errorf("got unexpected error generating config: %s", err) t.Errorf("got unexpected error generating config: %v", err)
return return
} }
if err == nil && test.shouldErr { if err == nil && test.shouldErr {

View File

@ -96,7 +96,7 @@ func TestVersionIsBetween(t *testing.T) {
func TestParseKubernetesVersion(t *testing.T) { func TestParseKubernetesVersion(t *testing.T) {
version, err := ParseKubernetesVersion("v1.8.0-alpha.5") version, err := ParseKubernetesVersion("v1.8.0-alpha.5")
if err != nil { if err != nil {
t.Fatalf("Error parsing version: %s", err) t.Fatalf("Error parsing version: %v", err)
} }
if version.NE(semver.MustParse("1.8.0-alpha.5")) { if version.NE(semver.MustParse("1.8.0-alpha.5")) {
t.Errorf("Expected: %s, Actual:%s", "1.8.0-alpha.5", version) t.Errorf("Expected: %s, Actual:%s", "1.8.0-alpha.5", version)
@ -141,7 +141,7 @@ func TestParseFeatureArgs(t *testing.T) {
kubeadm, component, err := ParseFeatureArgs(test.featureGates) kubeadm, component, err := ParseFeatureArgs(test.featureGates)
if err != nil { if err != nil {
t.Fatalf("Error parsing feature args: %s", err) t.Fatalf("Error parsing feature args: %v", err)
} }
if !reflect.DeepEqual(kubeadm, test.expectedKubeadmFeatureArgs) { if !reflect.DeepEqual(kubeadm, test.expectedKubeadmFeatureArgs) {

View File

@ -229,7 +229,7 @@ func TestDeleteHost(t *testing.T) {
createHost(api, defaultMachineConfig) createHost(api, defaultMachineConfig)
if err := DeleteHost(api); err != nil { if err := DeleteHost(api); err != nil {
t.Fatalf("Unexpected error deleting host: %s", err) t.Fatalf("Unexpected error deleting host: %v", err)
} }
} }
@ -274,7 +274,7 @@ func TestDeleteHostMultipleErrors(t *testing.T) {
expectedErrors := []string{"error removing " + config.GetMachineName(), "error deleting machine"} expectedErrors := []string{"error removing " + config.GetMachineName(), "error deleting machine"}
for _, expectedError := range expectedErrors { for _, expectedError := range expectedErrors {
if !strings.Contains(err.Error(), expectedError) { if !strings.Contains(err.Error(), expectedError) {
t.Fatalf("Error %s expected to contain: %s.", err, expectedError) t.Fatalf("Error %v expected to contain: %s.", err, expectedError)
} }
} }
} }
@ -285,7 +285,7 @@ func TestGetHostStatus(t *testing.T) {
checkState := func(expected string) { checkState := func(expected string) {
s, err := GetHostStatus(api) s, err := GetHostStatus(api)
if err != nil { if err != nil {
t.Fatalf("Unexpected error getting status: %s", err) t.Fatalf("Unexpected error getting status: %v", err)
} }
if s != expected { if s != expected {
t.Fatalf("Expected status: %s, got %s", s, expected) t.Fatalf("Expected status: %s, got %s", s, expected)
@ -319,7 +319,7 @@ func TestGetHostDockerEnv(t *testing.T) {
envMap, err := GetHostDockerEnv(api) envMap, err := GetHostDockerEnv(api)
if err != nil { if err != nil {
t.Fatalf("Unexpected error getting env: %s", err) t.Fatalf("Unexpected error getting env: %v", err)
} }
dockerEnvKeys := [...]string{ dockerEnvKeys := [...]string{
@ -352,7 +352,7 @@ func TestGetHostDockerEnvIPv6(t *testing.T) {
envMap, err := GetHostDockerEnv(api) envMap, err := GetHostDockerEnv(api)
if err != nil { if err != nil {
t.Fatalf("Unexpected error getting env: %s", err) t.Fatalf("Unexpected error getting env: %v", err)
} }
expected := "tcp://[fe80::215:5dff:fe00:a903]:2376" expected := "tcp://[fe80::215:5dff:fe00:a903]:2376"
@ -368,7 +368,7 @@ func TestCreateSSHShell(t *testing.T) {
s, _ := tests.NewSSHServer() s, _ := tests.NewSSHServer()
port, err := s.Start() port, err := s.Start()
if err != nil { if err != nil {
t.Fatalf("Error starting ssh server: %s", err) t.Fatalf("Error starting ssh server: %v", err)
} }
d := &tests.MockDriver{ d := &tests.MockDriver{
@ -383,7 +383,7 @@ func TestCreateSSHShell(t *testing.T) {
cliArgs := []string{"exit"} cliArgs := []string{"exit"}
if err := CreateSSHShell(api, cliArgs); err != nil { if err := CreateSSHShell(api, cliArgs); err != nil {
t.Fatalf("Error running ssh command: %s", err) t.Fatalf("Error running ssh command: %v", err)
} }
if !s.IsSessionRequested() { if !s.IsSessionRequested() {

View File

@ -62,7 +62,7 @@ func detectVBoxManageCmd() string {
func findVBoxInstallDirInRegistry() (string, error) { func findVBoxInstallDirInRegistry() (string, error) {
registryKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Oracle\VirtualBox`, registry.QUERY_VALUE) registryKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Oracle\VirtualBox`, registry.QUERY_VALUE)
if err != nil { if err != nil {
errorMessage := fmt.Sprintf("Can't find VirtualBox registry entries, is VirtualBox really installed properly? %s", err) errorMessage := fmt.Sprintf("Can't find VirtualBox registry entries, is VirtualBox really installed properly? %v", err)
glog.Errorf(errorMessage) glog.Errorf(errorMessage)
return "", errors.New(errorMessage) return "", errors.New(errorMessage)
} }
@ -71,7 +71,7 @@ func findVBoxInstallDirInRegistry() (string, error) {
installDir, _, err := registryKey.GetStringValue("InstallDir") installDir, _, err := registryKey.GetStringValue("InstallDir")
if err != nil { if err != nil {
errorMessage := fmt.Sprintf("Can't find InstallDir registry key within VirtualBox registries entries, is VirtualBox really installed properly? %s", err) errorMessage := fmt.Sprintf("Can't find InstallDir registry key within VirtualBox registries entries, is VirtualBox really installed properly? %v", err)
glog.Errorf(errorMessage) glog.Errorf(errorMessage)
return "", errors.New(errorMessage) return "", errors.New(errorMessage)
} }

View File

@ -65,13 +65,13 @@ func ReadConfig() (MinikubeConfig, error) {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return make(map[string]interface{}), nil return make(map[string]interface{}), nil
} }
return nil, fmt.Errorf("Could not open file %s: %s", constants.ConfigFile, err) return nil, fmt.Errorf("Could not open file %s: %v", constants.ConfigFile, err)
} }
defer f.Close() defer f.Close()
m, err := decode(f) m, err := decode(f)
if err != nil { if err != nil {
return nil, fmt.Errorf("Could not decode config %s: %s", constants.ConfigFile, err) return nil, fmt.Errorf("Could not decode config %s: %v", constants.ConfigFile, err)
} }
return m, nil return m, nil

View File

@ -26,7 +26,7 @@ import (
func TestReplaceWinDriveLetterToVolumeName(t *testing.T) { func TestReplaceWinDriveLetterToVolumeName(t *testing.T) {
path, err := ioutil.TempDir("", "repwindl2vn") path, err := ioutil.TempDir("", "repwindl2vn")
if err != nil { if err != nil {
t.Fatalf("Error make tmp directory: %s", err) t.Fatalf("Error make tmp directory: %v", err)
} }
defer os.RemoveAll(path) defer os.RemoveAll(path)
@ -40,7 +40,7 @@ func TestReplaceWinDriveLetterToVolumeName(t *testing.T) {
} }
if _, err := replaceWinDriveLetterToVolumeName(path); err != nil { if _, err := replaceWinDriveLetterToVolumeName(path); err != nil {
t.Errorf("Error replace a Windows drive letter to a volume name: %s", err) t.Errorf("Error replace a Windows drive letter to a volume name: %v", err)
} }
} }

View File

@ -102,7 +102,7 @@ func TestLocalClientNewHost(t *testing.T) {
} }
} }
if err != nil && !test.err { if err != nil && !test.err {
t.Errorf("Unexpected error: %s", err) t.Errorf("Unexpected error: %v", err)
} }
if err == nil && test.err { if err == nil && test.err {
t.Errorf("No error returned, but expected err") t.Errorf("No error returned, but expected err")

View File

@ -78,7 +78,7 @@ func (*K8sClientGetter) GetClientset() (*kubernetes.Clientset, error) {
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides) kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
clientConfig, err := kubeConfig.ClientConfig() clientConfig, err := kubeConfig.ClientConfig()
if err != nil { if err != nil {
return nil, fmt.Errorf("Error creating kubeConfig: %s", err) return nil, fmt.Errorf("Error creating kubeConfig: %v", err)
} }
clientConfig.Timeout = 1 * time.Second clientConfig.Timeout = 1 * time.Second
client, err := kubernetes.NewForConfig(clientConfig) client, err := kubernetes.NewForConfig(clientConfig)

View File

@ -236,7 +236,7 @@ func TestPrintURLsForService(t *testing.T) {
t.Parallel() t.Parallel()
urls, err := printURLsForService(client, "127.0.0.1", test.serviceName, test.namespace, test.tmpl) urls, err := printURLsForService(client, "127.0.0.1", test.serviceName, test.namespace, test.tmpl)
if err != nil && !test.err { if err != nil && !test.err {
t.Errorf("Error: %s", err) t.Errorf("Error: %v", err)
} }
if err == nil && test.err { if err == nil && test.err {
t.Errorf("Expected error but got none") t.Errorf("Expected error but got none")
@ -364,7 +364,7 @@ func TestGetServiceURLs(t *testing.T) {
} }
urls, err := GetServiceURLs(test.api, test.namespace, defaultTemplate) urls, err := GetServiceURLs(test.api, test.namespace, defaultTemplate)
if err != nil && !test.err { if err != nil && !test.err {
t.Errorf("Error GetServiceURLs %s", err) t.Errorf("Error GetServiceURLs %v", err)
} }
if err == nil && test.err { if err == nil && test.err {
t.Errorf("Test should have failed, but didn't") t.Errorf("Test should have failed, but didn't")
@ -431,7 +431,7 @@ func TestGetServiceURLsForService(t *testing.T) {
} }
urls, err := GetServiceURLsForService(test.api, test.namespace, test.service, defaultTemplate) urls, err := GetServiceURLsForService(test.api, test.namespace, test.service, defaultTemplate)
if err != nil && !test.err { if err != nil && !test.err {
t.Errorf("Error GetServiceURLsForService %s", err) t.Errorf("Error GetServiceURLsForService %v", err)
} }
if err == nil && test.err { if err == nil && test.err {
t.Errorf("Test should have failed, but didn't") t.Errorf("Test should have failed, but didn't")

View File

@ -28,7 +28,7 @@ func TestNewSSHClient(t *testing.T) {
s, _ := tests.NewSSHServer() s, _ := tests.NewSSHServer()
port, err := s.Start() port, err := s.Start()
if err != nil { if err != nil {
t.Fatalf("Error starting ssh server: %s", err) t.Fatalf("Error starting ssh server: %v", err)
} }
d := &tests.MockDriver{ d := &tests.MockDriver{
Port: port, Port: port,
@ -39,7 +39,7 @@ func TestNewSSHClient(t *testing.T) {
} }
c, err := NewSSHClient(d) c, err := NewSSHClient(d)
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %s", err) t.Fatalf("Unexpected error: %v", err)
} }
cmd := "foo" cmd := "foo"
@ -75,7 +75,7 @@ func TestNewSSHHost(t *testing.T) {
h, err := newSSHHost(&d) h, err := newSSHHost(&d)
if err != nil { if err != nil {
t.Fatalf("Unexpected error creating host: %s", err) t.Fatalf("Unexpected error creating host: %v", err)
} }
if h.SSHKeyPath != sshKeyPath { if h.SSHKeyPath != sshKeyPath {

View File

@ -120,7 +120,7 @@ func (s *SSHServer) Start() (int, error) {
// Note: string(req.Payload) adds additional characters to start of input. // Note: string(req.Payload) adds additional characters to start of input.
var cmd execRequest var cmd execRequest
if err := ssh.Unmarshal(req.Payload, &cmd); err != nil { if err := ssh.Unmarshal(req.Payload, &cmd); err != nil {
glog.Errorf("Unmarshall encountered error: %s with req: %v", err, req.Type) glog.Errorf("Unmarshall encountered error: %v with req: %v", err, req.Type)
return return
} }
s.Commands[cmd.Command] = 1 s.Commands[cmd.Command] = 1

View File

@ -208,7 +208,7 @@ CRIO_MINIKUBE_OPTIONS='{{ range .EngineOptions.InsecureRegistry }}--insecure-reg
// This is unlikely to cause issues unless the user has explicitly requested CRIO, so just log a warning. // This is unlikely to cause issues unless the user has explicitly requested CRIO, so just log a warning.
if err := p.Service("crio", serviceaction.Restart); err != nil { if err := p.Service("crio", serviceaction.Restart); err != nil {
log.Warn("Unable to restart crio service. Error: %s", err) log.Warn("Unable to restart crio service. Error: %v", err)
} }
return nil return nil
@ -264,7 +264,7 @@ func configureAuth(p *BuildrootProvisioner) error {
}) })
if err != nil { if err != nil {
return fmt.Errorf("error generating server cert: %s", err) return fmt.Errorf("error generating server cert: %v", err)
} }
remoteCerts := map[string]string{ remoteCerts := map[string]string{

View File

@ -66,19 +66,19 @@ func setElement(e reflect.Value, v string) error {
case net.IPNet: case net.IPNet:
_, cidr, err := net.ParseCIDR(v) _, cidr, err := net.ParseCIDR(v)
if err != nil { if err != nil {
return fmt.Errorf("Error converting input %s to a CIDR: %s", v, err) return fmt.Errorf("Error converting input %s to a CIDR: %v", v, err)
} }
e.Set(reflect.ValueOf(*cidr)) e.Set(reflect.ValueOf(*cidr))
case utilnet.PortRange: case utilnet.PortRange:
pr, err := utilnet.ParsePortRange(v) pr, err := utilnet.ParsePortRange(v)
if err != nil { if err != nil {
return fmt.Errorf("Error converting input %s to PortRange: %s", v, err) return fmt.Errorf("Error converting input %s to PortRange: %v", v, err)
} }
e.Set(reflect.ValueOf(*pr)) e.Set(reflect.ValueOf(*pr))
case time.Duration: case time.Duration:
dur, err := time.ParseDuration(v) dur, err := time.ParseDuration(v)
if err != nil { if err != nil {
return fmt.Errorf("Error converting input %s to Duration: %s", v, err) return fmt.Errorf("Error converting input %s to Duration: %v", v, err)
} }
e.Set(reflect.ValueOf(dur)) e.Set(reflect.ValueOf(dur))
case []string: case []string:
@ -126,7 +126,7 @@ func convertMap(e reflect.Value, v string) error {
func convertInt(e reflect.Value, v string) error { func convertInt(e reflect.Value, v string) error {
i, err := strconv.Atoi(v) i, err := strconv.Atoi(v)
if err != nil { if err != nil {
return fmt.Errorf("Error converting input %s to an integer: %s", v, err) return fmt.Errorf("Error converting input %s to an integer: %v", v, err)
} }
e.SetInt(int64(i)) e.SetInt(int64(i))
return nil return nil
@ -140,7 +140,7 @@ func convertString(e reflect.Value, v string) error {
func convertFloat(e reflect.Value, v string) error { func convertFloat(e reflect.Value, v string) error {
f, err := strconv.ParseFloat(v, 64) f, err := strconv.ParseFloat(v, 64)
if err != nil { if err != nil {
return fmt.Errorf("Error converting input %s to a float: %s", v, err) return fmt.Errorf("Error converting input %s to a float: %v", v, err)
} }
e.SetFloat(f) e.SetFloat(f)
return nil return nil
@ -149,7 +149,7 @@ func convertFloat(e reflect.Value, v string) error {
func convertBool(e reflect.Value, v string) error { func convertBool(e reflect.Value, v string) error {
b, err := strconv.ParseBool(v) b, err := strconv.ParseBool(v)
if err != nil { if err != nil {
return fmt.Errorf("Error converting input %s to a bool: %s", v, err) return fmt.Errorf("Error converting input %s to a bool: %v", v, err)
} }
e.SetBool(b) e.SetBool(b)
return nil return nil

View File

@ -104,7 +104,7 @@ func TestFindNestedStrings(t *testing.T) {
} { } {
v, err := findNestedElement(tc.input, &a) v, err := findNestedElement(tc.input, &a)
if err != nil { if err != nil {
t.Fatalf("Did not expect error. Got: %s", err) t.Fatalf("Did not expect error. Got: %v", err)
} }
if v.String() != tc.output { if v.String() != tc.output {
t.Fatalf("Expected: %s, got %s", tc.output, v.String()) t.Fatalf("Expected: %s, got %s", tc.output, v.String())
@ -126,7 +126,7 @@ func TestFindNestedInts(t *testing.T) {
} { } {
v, err := findNestedElement(tc.input, &a) v, err := findNestedElement(tc.input, &a)
if err != nil { if err != nil {
t.Fatalf("Did not expect error. Got: %s", err) t.Fatalf("Did not expect error. Got: %v", err)
} }
if v.Int() != tc.output { if v.Int() != tc.output {
t.Fatalf("Expected: %d, got %d", tc.output, v.Int()) t.Fatalf("Expected: %d, got %d", tc.output, v.Int())
@ -151,7 +151,7 @@ func TestFindNestedFloats(t *testing.T) {
} { } {
v, err := findNestedElement(tc.input, &a) v, err := findNestedElement(tc.input, &a)
if err != nil { if err != nil {
t.Fatalf("Did not expect error. Got: %s", err) t.Fatalf("Did not expect error. Got: %v", err)
} }
// Floating point comparison is tricky. // Floating point comparison is tricky.
@ -187,7 +187,7 @@ func TestSetElement(t *testing.T) {
} { } {
a := buildConfig() a := buildConfig()
if err := FindAndSet(tc.path, &a, tc.newval); err != nil { if err := FindAndSet(tc.path, &a, tc.newval); err != nil {
t.Fatalf("Error setting value: %s", err) t.Fatalf("Error setting value: %v", err)
} }
if !tc.checker(a) { if !tc.checker(a) {
t.Fatalf("Error, values not correct: %v, %s, %s", a, tc.newval, tc.path) t.Fatalf("Error, values not correct: %v, %s, %s", a, tc.newval, tc.path)

View File

@ -59,7 +59,7 @@ func TestCacheMinikubeISOFromURL(t *testing.T) {
})) }))
isoURL := server.URL + "/minikube-test.iso" isoURL := server.URL + "/minikube-test.iso"
if err := dler.CacheMinikubeISOFromURL(isoURL); err != nil { if err := dler.CacheMinikubeISOFromURL(isoURL); err != nil {
t.Fatalf("Unexpected error from CacheMinikubeISOFromURL: %s", err) t.Fatalf("Unexpected error from CacheMinikubeISOFromURL: %v", err)
} }
transferred, err := ioutil.ReadFile(filepath.Join(isoPath)) transferred, err := ioutil.ReadFile(filepath.Join(isoPath))

View File

@ -70,7 +70,7 @@ func TestValidFlags(t *testing.T) {
var e ExtraOptionSlice var e ExtraOptionSlice
flags.Var(&e, "e", "usage") flags.Var(&e, "e", "usage")
if err := flags.Parse(tc.args); err != nil { if err := flags.Parse(tc.args); err != nil {
t.Errorf("Unexpected error: %s for %s.", err, tc) t.Errorf("Unexpected error: %v for %s.", err, tc)
} }
if !reflect.DeepEqual(e, tc.values) { if !reflect.DeepEqual(e, tc.values) {

View File

@ -143,7 +143,7 @@ func TestSetupKubeConfig(t *testing.T) {
t.Parallel() t.Parallel()
tmpDir, err := ioutil.TempDir("", "") tmpDir, err := ioutil.TempDir("", "")
if err != nil { if err != nil {
t.Fatalf("Error making temp directory %s", err) t.Fatalf("Error making temp directory %v", err)
} }
test.cfg.SetKubeConfigFile(filepath.Join(tmpDir, "kubeconfig")) test.cfg.SetKubeConfigFile(filepath.Join(tmpDir, "kubeconfig"))
if len(test.existingCfg) != 0 { if len(test.existingCfg) != 0 {
@ -151,14 +151,14 @@ func TestSetupKubeConfig(t *testing.T) {
} }
err = SetupKubeConfig(test.cfg) err = SetupKubeConfig(test.cfg)
if err != nil && !test.err { if err != nil && !test.err {
t.Errorf("Got unexpected error: %s", err) t.Errorf("Got unexpected error: %v", err)
} }
if err == nil && test.err { if err == nil && test.err {
t.Errorf("Expected error but got none") t.Errorf("Expected error but got none")
} }
config, err := ReadConfigOrNew(test.cfg.GetKubeConfigFile()) config, err := ReadConfigOrNew(test.cfg.GetKubeConfigFile())
if err != nil { if err != nil {
t.Errorf("Error reading kubeconfig file: %s", err) t.Errorf("Error reading kubeconfig file: %v", err)
} }
if test.cfg.KeepContext && config.CurrentContext == test.cfg.ClusterName { if test.cfg.KeepContext && config.CurrentContext == test.cfg.ClusterName {
t.Errorf("Context was changed even though KeepContext was true") t.Errorf("Context was changed even though KeepContext was true")
@ -213,10 +213,10 @@ func TestGetKubeConfigStatus(t *testing.T) {
configFilename := tempFile(t, test.existing) configFilename := tempFile(t, test.existing)
statusActual, err := GetKubeConfigStatus(test.ip, configFilename, "minikube") statusActual, err := GetKubeConfigStatus(test.ip, configFilename, "minikube")
if err != nil && !test.err { if err != nil && !test.err {
t.Errorf("Got unexpected error: %s", err) t.Errorf("Got unexpected error: %v", err)
} }
if err == nil && test.err { if err == nil && test.err {
t.Errorf("Expected error but got none: %s", err) t.Errorf("Expected error but got none: %v", err)
} }
if test.status != statusActual { if test.status != statusActual {
t.Errorf("Expected status %t, but got %t", test.status, statusActual) t.Errorf("Expected status %t, but got %t", test.status, statusActual)
@ -270,10 +270,10 @@ func TestUpdateKubeconfigIP(t *testing.T) {
configFilename := tempFile(t, test.existing) configFilename := tempFile(t, test.existing)
statusActual, err := UpdateKubeconfigIP(test.ip, configFilename, "minikube") statusActual, err := UpdateKubeconfigIP(test.ip, configFilename, "minikube")
if err != nil && !test.err { if err != nil && !test.err {
t.Errorf("Got unexpected error: %s", err) t.Errorf("Got unexpected error: %v", err)
} }
if err == nil && test.err { if err == nil && test.err {
t.Errorf("Expected error but got none: %s", err) t.Errorf("Expected error but got none: %v", err)
} }
if test.status != statusActual { if test.status != statusActual {
t.Errorf("Expected status %t, but got %t", test.status, statusActual) t.Errorf("Expected status %t, but got %t", test.status, statusActual)
@ -357,10 +357,10 @@ func TestGetIPFromKubeConfig(t *testing.T) {
configFilename := tempFile(t, test.cfg) configFilename := tempFile(t, test.cfg)
ip, err := getIPFromKubeConfig(configFilename, "minikube") ip, err := getIPFromKubeConfig(configFilename, "minikube")
if err != nil && !test.err { if err != nil && !test.err {
t.Errorf("Got unexpected error: %s", err) t.Errorf("Got unexpected error: %v", err)
} }
if err == nil && test.err { if err == nil && test.err {
t.Errorf("Expected error but got none: %s", err) t.Errorf("Expected error but got none: %v", err)
} }
if !ip.Equal(test.ip) { if !ip.Equal(test.ip) {
t.Errorf("IP returned: %s does not match ip given: %s", ip, test.ip) t.Errorf("IP returned: %s does not match ip given: %s", ip, test.ip)

View File

@ -66,7 +66,7 @@ func GetClient() (kubernetes.Interface, error) {
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides) kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
config, err := kubeConfig.ClientConfig() config, err := kubeConfig.ClientConfig()
if err != nil { if err != nil {
return nil, fmt.Errorf("Error creating kubeConfig: %s", err) return nil, fmt.Errorf("Error creating kubeConfig: %v", err)
} }
client, err := kubernetes.NewForConfig(config) client, err := kubernetes.NewForConfig(config)
if err != nil { if err != nil {

View File

@ -46,7 +46,7 @@ func (r RetriableError) Error() string { return "Temporary Error: " + r.Err.Erro
func CalculateDiskSizeInMB(humanReadableDiskSize string) int { func CalculateDiskSizeInMB(humanReadableDiskSize string) int {
diskSize, err := units.FromHumanSize(humanReadableDiskSize) diskSize, err := units.FromHumanSize(humanReadableDiskSize)
if err != nil { if err != nil {
glog.Errorf("Invalid disk size: %s", err) glog.Errorf("Invalid disk size: %v", err)
} }
return int(diskSize / units.MB) return int(diskSize / units.MB)
} }

View File

@ -130,12 +130,12 @@ func TestMultiError(t *testing.T) {
expected := `Error 1 expected := `Error 1
Error 2` Error 2`
if err.Error() != expected { if err.Error() != expected {
t.Fatalf("%s != %s", err, expected) t.Fatalf("%s != %s", err.Error(), expected)
} }
m = MultiError{} m = MultiError{}
if err := m.ToError(); err != nil { if err := m.ToError(); err != nil {
t.Fatalf("Unexpected error: %s", err) t.Fatalf("Unexpected error: %v", err)
} }
} }

View File

@ -48,7 +48,7 @@ func testClusterDNS(t *testing.T) {
// The query result is not as important as service reachability // The query result is not as important as service reachability
out, err := kr.RunCommand([]string{"exec", busybox, "nslookup", "localhost"}) out, err := kr.RunCommand([]string{"exec", busybox, "nslookup", "localhost"})
if err != nil { if err != nil {
t.Errorf("nslookup within busybox failed: %s", err) t.Errorf("nslookup within busybox failed: %v", err)
} }
clusterIP := []byte("10.96.0.1") clusterIP := []byte("10.96.0.1")
if !bytes.Contains(out, clusterIP) { if !bytes.Contains(out, clusterIP) {
@ -73,7 +73,7 @@ func busyBoxPod(t *testing.T, c kubernetes.Interface, kr *util.KubectlRunner) st
} }
// TODO(tstromberg): Refactor WaitForBusyboxRunning to return name of pod. // TODO(tstromberg): Refactor WaitForBusyboxRunning to return name of pod.
if err := util.WaitForBusyboxRunning(t, "default"); err != nil { if err := util.WaitForBusyboxRunning(t, "default"); err != nil {
t.Fatalf("Waiting for busybox pod to be up: %s", err) t.Fatalf("Waiting for busybox pod to be up: %v", err)
} }
pods, err := c.CoreV1().Pods("default").List(metav1.ListOptions{LabelSelector: "integration-test=busybox"}) pods, err := c.CoreV1().Pods("default").List(metav1.ListOptions{LabelSelector: "integration-test=busybox"})

View File

@ -62,6 +62,6 @@ func testClusterEnv(t *testing.T) {
return nil return nil
} }
if err := util.Retry(t, dockerPs, 3*time.Second, 5); err != nil { if err := util.Retry(t, dockerPs, 3*time.Second, 5); err != nil {
t.Fatalf("Error running command: %s. Error: %s Output: %s", "docker ps", err, output) t.Fatalf("Error running command: %s. Error: %v Output: %s", "docker ps", err, output)
} }
} }

View File

@ -32,8 +32,7 @@ func TestDocker(t *testing.T) {
} }
minikubeRunner.RunCommand("delete", false) minikubeRunner.RunCommand("delete", false)
startCmd := fmt.Sprintf("start %s %s %s", minikubeRunner.StartArgs, minikubeRunner.Args, startCmd := fmt.Sprintf("start %s %s %s", minikubeRunner.StartArgs, minikubeRunner.Args, "--docker-env=FOO=BAR --docker-env=BAZ=BAT --docker-opt=debug --docker-opt=icc=true")
"--docker-env=FOO=BAR --docker-env=BAZ=BAT --docker-opt=debug --docker-opt=icc=true")
minikubeRunner.RunCommand(startCmd, true) minikubeRunner.RunCommand(startCmd, true)
minikubeRunner.EnsureRunning() minikubeRunner.EnsureRunning()

View File

@ -32,7 +32,7 @@ func TestMain(m *testing.M) {
var binaryPath = flag.String("binary", "../../out/minikube", "path to minikube binary") var binaryPath = flag.String("binary", "../../out/minikube", "path to minikube binary")
var args = flag.String("minikube-args", "", "Arguments to pass to minikube") var args = flag.String("minikube-args", "", "Arguments to pass to minikube")
var startArgs = flag.String("minikube-start-args", "", "Arguments to pass to minikube start") var startArgs = flag.String("minikube-start-args", "", "Arguments to pass to minikube start")
var testdataDir = flag.String("testdata-dir", "testdata", "source of testdata relative to test/integration") var testdataDir = flag.String("testdata-dir", "testdata", "the directory relative to test/integration where the testdata lives")
func NewMinikubeRunner(t *testing.T) util.MinikubeRunner { func NewMinikubeRunner(t *testing.T) util.MinikubeRunner {
return util.MinikubeRunner{ return util.MinikubeRunner{

View File

@ -74,7 +74,7 @@ func testPackages(t *testing.T) {
for _, pkg := range packages { for _, pkg := range packages {
if output, err := minikubeRunner.SSH(fmt.Sprintf("which %s", pkg)); err != nil { if output, err := minikubeRunner.SSH(fmt.Sprintf("which %s", pkg)); err != nil {
t.Errorf("Error finding package: %s. Error: %s. Output: %s", pkg, err, output) t.Errorf("Error finding package: %s. Error: %v. Output: %s", pkg, err, output)
} }
} }
@ -94,7 +94,7 @@ func testPersistence(t *testing.T) {
} { } {
output, err := minikubeRunner.SSH(fmt.Sprintf("df %s | tail -n 1 | awk '{print $1}'", dir)) output, err := minikubeRunner.SSH(fmt.Sprintf("df %s | tail -n 1 | awk '{print $1}'", dir))
if err != nil { if err != nil {
t.Errorf("Error checking device for %s. Error: %s.", dir, err) t.Errorf("Error checking device for %s. Error: %v", dir, err)
} }
if !strings.Contains(output, "/dev/sda1") { if !strings.Contains(output, "/dev/sda1") {
t.Errorf("Path %s is not mounted persistently. %s", dir, output) t.Errorf("Path %s is not mounted persistently. %s", dir, output)

View File

@ -65,7 +65,7 @@ func testMounting(t *testing.T) {
path := filepath.Join(tempDir, file) path := filepath.Join(tempDir, file)
err = ioutil.WriteFile(path, []byte(expected), 0644) err = ioutil.WriteFile(path, []byte(expected), 0644)
if err != nil { if err != nil {
t.Fatalf("Unexpected error while writing file %s: %s.", path, err) t.Fatalf("Unexpected error while writing file %s: %v", path, err)
} }
} }
@ -123,13 +123,13 @@ func testMounting(t *testing.T) {
// test that frompodremove can be deleted on the host // test that frompodremove can be deleted on the host
path = filepath.Join(tempDir, "frompodremove") path = filepath.Join(tempDir, "frompodremove")
if err := os.Remove(path); err != nil { if err := os.Remove(path); err != nil {
t.Fatalf("Unexpected error removing file %s: %s", path, err) t.Fatalf("Unexpected error removing file %s: %v", path, err)
} }
return nil return nil
} }
if err := util.Retry(t, mountTest, 5*time.Second, 40); err != nil { if err := util.Retry(t, mountTest, 5*time.Second, 40); err != nil {
t.Fatal("mountTest failed with error:", err) t.Fatalf("mountTest failed with error: %v", err)
} }
} }

View File

@ -60,7 +60,7 @@ func testProvisioning(t *testing.T) {
if len(scl.Items) > 0 { if len(scl.Items) > 0 {
return nil return nil
} }
return fmt.Errorf("no StorageClass yet") return fmt.Errorf("No default StorageClass yet.")
} }
if err := util.Retry(t, checkStorageClass, 5*time.Second, 20); err != nil { if err := util.Retry(t, checkStorageClass, 5*time.Second, 20); err != nil {
@ -83,13 +83,13 @@ func testProvisioning(t *testing.T) {
} }
if err := checkPodRunning(); err != nil { if err := checkPodRunning(); err != nil {
t.Fatal("Check storage-provisioner pod running failed with error: ", err) t.Fatalf("Check storage-provisioner pod running failed with error: %v", err)
} }
// Now create the PVC // Now create the PVC
pvcPath := filepath.Join(*testdataDir, "pvc.yaml") pvcPath := filepath.Join(*testdataDir, "pvc.yaml")
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", pvcPath}); err != nil { if _, err := kubectlRunner.RunCommand([]string{"create", "-f", pvcPath}); err != nil {
t.Fatalf("Error creating pvc") t.Fatalf("Error creating pvc: %v", err)
} }
// And check that it gets bound to a PV. // And check that it gets bound to a PV.
@ -106,7 +106,7 @@ func testProvisioning(t *testing.T) {
} }
if err := util.Retry(t, checkStorage, 2*time.Second, 5); err != nil { if err := util.Retry(t, checkStorage, 2*time.Second, 5); err != nil {
t.Fatal("PV Creation failed with error:", err) t.Fatalf("PV Creation failed with error: %v", err)
} }
} }

View File

@ -75,7 +75,7 @@ func (m *MinikubeRunner) RunCommand(command string, checkError bool) string {
if exitError, ok := err.(*exec.ExitError); ok { if exitError, ok := err.(*exec.ExitError); ok {
m.T.Fatalf("Error running command: %s %s. Output: %s", command, exitError.Stderr, stdout) m.T.Fatalf("Error running command: %s %s. Output: %s", command, exitError.Stderr, stdout)
} else { } else {
m.T.Fatalf("Error running command: %s %s. Output: %s", command, err, stdout) m.T.Fatalf("Error running command: %s %v. Output: %s", command, err, stdout)
} }
} }
return string(stdout) return string(stdout)
@ -87,7 +87,7 @@ func (m *MinikubeRunner) RunDaemon(command string) (*exec.Cmd, *bufio.Reader) {
cmd := exec.Command(path, commandArr...) cmd := exec.Command(path, commandArr...)
stdoutPipe, err := cmd.StdoutPipe() stdoutPipe, err := cmd.StdoutPipe()
if err != nil { if err != nil {
m.T.Fatalf("stdout pipe failed: %v", err) m.T.Fatalf("stdout pipe failed: %s %v", command, err)
} }
err = cmd.Start() err = cmd.Start()
@ -183,7 +183,7 @@ func (k *KubectlRunner) RunCommand(args []string) (stdout []byte, err error) {
cmd := exec.Command(k.BinaryPath, args...) cmd := exec.Command(k.BinaryPath, args...)
stdout, err = cmd.CombinedOutput() stdout, err = cmd.CombinedOutput()
if err != nil { if err != nil {
k.T.Logf("Error %s running command %s. Return code: %s", stdout, args, err) k.T.Logf("Error %s running command %s. Return code: %v", stdout, args, err)
return &commonutil.RetriableError{Err: fmt.Errorf("Error running command: %v. Output: %s", err, stdout)} return &commonutil.RetriableError{Err: fmt.Errorf("Error running command: %v. Output: %s", err, stdout)}
} }
return nil return nil