Cleanup some "go vet" and "go lint" errors.

We should automate these checks...
pull/554/head
Dan Lorenc 2016-09-06 20:47:12 -07:00
parent 12dfb47bca
commit 6219286cae
9 changed files with 16 additions and 18 deletions

View File

@ -43,7 +43,7 @@ type Setting struct {
// These are all the settings that are configurable // These are all the settings that are configurable
// and their validation and callback fn run on Set // and their validation and callback fn run on Set
var settings []Setting = []Setting{ var settings = []Setting{
{ {
name: "vm-driver", name: "vm-driver",
set: SetString, set: SetString,
@ -102,7 +102,7 @@ var ConfigCmd = &cobra.Command{
}, },
} }
// Reads in the JSON minikube config // ReadConfig reads in the JSON minikube config
func ReadConfig() (MinikubeConfig, error) { func ReadConfig() (MinikubeConfig, error) {
f, err := os.Open(constants.ConfigFile) f, err := os.Open(constants.ConfigFile)
if err != nil { if err != nil {
@ -111,8 +111,7 @@ func ReadConfig() (MinikubeConfig, error) {
} }
return nil, fmt.Errorf("Could not open file %s: %s", constants.ConfigFile, err) return nil, fmt.Errorf("Could not open file %s: %s", constants.ConfigFile, err)
} }
var m MinikubeConfig 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: %s", constants.ConfigFile, err)
} }
@ -120,7 +119,7 @@ func ReadConfig() (MinikubeConfig, error) {
return m, nil return m, nil
} }
// Writes a minikube config to the JSON file // WriteConfig writes a minikube config to the JSON file
func WriteConfig(m MinikubeConfig) error { func WriteConfig(m MinikubeConfig) error {
f, err := os.Create(constants.ConfigFile) f, err := os.Create(constants.ConfigFile)
if err != nil { if err != nil {

View File

@ -32,9 +32,8 @@ func run(name string, value string, fns []setFn) error {
} }
if len(errors) > 0 { if len(errors) > 0 {
return fmt.Errorf("%v", errors) return fmt.Errorf("%v", errors)
} else {
return nil
} }
return nil
} }
func findSetting(name string) (Setting, error) { func findSetting(name string) (Setting, error) {

View File

@ -48,7 +48,7 @@ var dashboardCmd = &cobra.Command{
service := "kubernetes-dashboard" service := "kubernetes-dashboard"
if err := commonutil.RetryAfter(20, func() error { return CheckService(namespace, service) }, 6*time.Second); err != nil { if err := commonutil.RetryAfter(20, func() error { return CheckService(namespace, service) }, 6*time.Second); err != nil {
fmt.Fprintln(os.Stderr, "Could not find finalized endpoint being pointed to by %s: %s", service, err) fmt.Fprintf(os.Stderr, "Could not find finalized endpoint being pointed to by %s: %s\n", service, err)
os.Exit(1) os.Exit(1)
} }

View File

@ -104,7 +104,7 @@ func shellCfgSet(api libmachine.API) (*ShellConfig, error) {
host, err := api.Load(constants.MachineName) host, err := api.Load(constants.MachineName)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error getting IP: ", err) return nil, fmt.Errorf("Error getting IP: %s", err)
} }
ip, err := host.Driver.GetIP() ip, err := host.Driver.GetIP()

View File

@ -55,7 +55,7 @@ var serviceCmd = &cobra.Command{
cluster.EnsureMinikubeRunningOrExit(api) cluster.EnsureMinikubeRunningOrExit(api)
if err := commonutil.RetryAfter(20, func() error { return CheckService(namespace, service) }, 6*time.Second); err != nil { if err := commonutil.RetryAfter(20, func() error { return CheckService(namespace, service) }, 6*time.Second); err != nil {
fmt.Fprintln(os.Stderr, "Could not find finalized endpoint being pointed to by %s: %s", service, err) fmt.Fprintf(os.Stderr, "Could not find finalized endpoint being pointed to by %s: %s\n", service, err)
os.Exit(1) os.Exit(1)
} }

View File

@ -94,7 +94,7 @@ func TestStartCluster(t *testing.T) {
for _, cmd := range []string{stopCommand, GetStartCommand(kubernetesConfig)} { for _, cmd := range []string{stopCommand, GetStartCommand(kubernetesConfig)} {
if _, ok := h.Commands[cmd]; !ok { if _, ok := h.Commands[cmd]; !ok {
t.Fatalf("Expected command not run: %s. Commands run: %s", cmd, h.Commands) t.Fatalf("Expected command not run: %s. Commands run: %v", cmd, h.Commands)
} }
} }
} }
@ -298,7 +298,7 @@ func TestDeleteHostMultipleErrors(t *testing.T) {
expectedErrors := []string{"Error removing " + constants.MachineName, "Error deleting machine"} expectedErrors := []string{"Error removing " + constants.MachineName, "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) t.Fatalf("Error %s expected to contain: %s.", err, expectedError)
} }
} }
} }
@ -477,11 +477,11 @@ func TestGetDashboardURL(t *testing.T) {
port, err := getServicePortFromServiceGetter(mockServiceGetter, "kubernetes-dashboard") port, err := getServicePortFromServiceGetter(mockServiceGetter, "kubernetes-dashboard")
if err != nil { if err != nil {
t.Fatalf("Error getting dashboard port from api: Error: ", err) t.Fatalf("Error getting dashboard port from api: Error: %s", err)
} }
expected := 1234 expected := 1234
if port != expected { if port != expected {
t.Fatalf("Error getting dashboard port from api: Expected: %s, Got: %s", port, expected) t.Fatalf("Error getting dashboard port from api: Expected: %d, Got: %d", port, expected)
} }
} }

View File

@ -54,7 +54,7 @@ func TestGetK8sVersionsFromURLCorrect(t *testing.T) {
} }
if len(k8sVersions) != 2 { // TODO(aprindle) change to len(handler....) if len(k8sVersions) != 2 { // TODO(aprindle) change to len(handler....)
//Check values here as well? Write eq method? //Check values here as well? Write eq method?
t.Fatalf("Expected two kubernetes versions from URL to be %s, it was instead %s", 2, len(k8sVersions)) t.Fatalf("Expected %d kubernetes versions from URL. Instead there were: %d", 2, len(k8sVersions))
} }
} }
@ -115,7 +115,7 @@ func TestPrintKubernetesVersions(t *testing.T) {
PrintKubernetesVersions(&outputBuffer, server.URL) PrintKubernetesVersions(&outputBuffer, server.URL)
if len(outputBuffer.String()) == 0 { if len(outputBuffer.String()) == 0 {
t.Fatalf("Expected PrintKubernetesVersion to output text as %s versions were served from URL but output was [%s]", t.Fatalf("Expected PrintKubernetesVersion to output text as %d versions were served from URL but output was [%s]",
2, outputBuffer.String()) //TODO(aprindle) change the 2 2, outputBuffer.String()) //TODO(aprindle) change the 2
} }
} }

View File

@ -113,7 +113,7 @@ func getLatestVersionFromURL(url string) (semver.Version, error) {
func writeTimeToFile(path string, inputTime time.Time) error { func writeTimeToFile(path string, inputTime time.Time) error {
err := ioutil.WriteFile(path, []byte(inputTime.Format(timeLayout)), 0644) err := ioutil.WriteFile(path, []byte(inputTime.Format(timeLayout)), 0644)
if err != nil { if err != nil {
return fmt.Errorf("Error writing current update time to file: ", err) return fmt.Errorf("Error writing current update time to file: %s", err)
} }
return nil return nil
} }

View File

@ -52,7 +52,7 @@ func Until(fn func() error, w io.Writer, name string, sleep time.Duration, done
} }
func Pad(str string) string { func Pad(str string) string {
return fmt.Sprint("\n%s\n", str) return fmt.Sprintf("\n%s\n", str)
} }
// If the file represented by path exists and // If the file represented by path exists and