From 997b9bd43caa59f3b9f8335f5427964427d1d005 Mon Sep 17 00:00:00 2001 From: jenson Date: Thu, 8 Nov 2018 14:27:35 +0530 Subject: [PATCH] [Amir/Jenson] changes based on PR feedback --- config/config.go | 3 +-- config/config_test.go | 9 ++------- daemon/client.go | 4 ++-- daemon/client_test.go | 2 +- io/printer_test_utils.go | 17 ----------------- proctord/utility/utils.go | 2 +- 6 files changed, 7 insertions(+), 30 deletions(-) delete mode 100644 io/printer_test_utils.go diff --git a/config/config.go b/config/config.go index 92aa0b58..d7bfa715 100644 --- a/config/config.go +++ b/config/config.go @@ -67,10 +67,9 @@ func LoadConfig() (ProctorConfig, ConfigError) { } // Returns Config file directory -// Returns /tmp if environment variable `ENVIRONMENT` is set to test, otherwise returns $HOME/.proctor // This allows to test on dev environment without conflicting with installed proctor config file func ConfigFileDir() string { - if os.Getenv("ENVIRONMENT") == "test" { + if os.Getenv(Environment) == "test" { return "/tmp" } else { return fmt.Sprintf("%s/.proctor", os.Getenv("HOME")) diff --git a/config/config_test.go b/config/config_test.go index 5a4f5f96..2762cc48 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -2,7 +2,6 @@ package config import ( "fmt" - "github.com/gojektech/proctor/io" "io/ioutil" "os" "testing" @@ -89,15 +88,11 @@ func TestShouldPrintInstructionsForConfigFileIfFileNotFound(t *testing.T) { configFilePath := fmt.Sprintf("%s/proctor.yaml", ConfigFileDir()) os.Remove(configFilePath) - mockPrinter := &io.MockPrinter{} - io.SetupMockPrinter(mockPrinter) - defer io.ResetPrinter() expectedMessage := fmt.Sprintf("Config file not found in %s\nCreate a config file with template:\n\nPROCTOR_HOST: \nEMAIL_ID: \nACCESS_TOKEN: \n", configFilePath) _, err := LoadConfig() assert.Equal(t, expectedMessage, err.Message) - mockPrinter.AssertExpectations(t) } func unsetEnvs() { @@ -108,9 +103,9 @@ func unsetEnvs() { } func createProctorConfigFile(t *testing.T, content string) string { - proctorHost := []byte(fmt.Sprintf(content)) + fileContent := []byte(fmt.Sprintf(content)) configFilePath := fmt.Sprintf("%s/proctor.yaml", ConfigFileDir()) - err := ioutil.WriteFile(configFilePath, proctorHost, 0644) + err := ioutil.WriteFile(configFilePath, fileContent, 0644) assert.NoError(t, err) return configFilePath } diff --git a/daemon/client.go b/daemon/client.go index fdf56027..b85544e0 100644 --- a/daemon/client.go +++ b/daemon/client.go @@ -57,8 +57,8 @@ func (c *client) ListProcs() ([]proc.Metadata, error) { resp, err := client.Do(req) if err != nil { - if err, ok := err.(net.Error); ok && err.Timeout() { - return []proc.Metadata{}, fmt.Errorf("%s\n%s\n%s", utility.GenericTimeoutErrorHeader, err.Error(), utility.GenericTimeoutErrorBody) + if netError, ok := err.(net.Error); ok && netError.Timeout() { + return []proc.Metadata{}, fmt.Errorf("%s\n%s\n%s", utility.GenericTimeoutErrorHeader, netError.Error(), utility.GenericTimeoutErrorBody) } return []proc.Metadata{}, fmt.Errorf("%s\n%s", utility.GenericNetworkErrorHeader, err.Error()) } diff --git a/daemon/client_test.go b/daemon/client_test.go index 21b7f82c..48c63886 100644 --- a/daemon/client_test.go +++ b/daemon/client_test.go @@ -105,7 +105,7 @@ func TestListProcsReturnClientSideTimeoutError(t *testing.T) { procList, err := proctorClient.ListProcs() - assert.Equal(t, errors.New("Connection Timeout!!!\nGet http://proctor.example.com/jobs/metadata: Unable to reach http://proctor.example.com/\nPlease check your Internet/VPN connection for connectivity to Proctor server."), err) + assert.Equal(t, errors.New("Connection Timeout!!!\nGet http://proctor.example.com/jobs/metadata: Unable to reach http://proctor.example.com/\nPlease check your Internet/VPN connection for connectivity to ProctorD."), err) assert.Equal(t, []proc.Metadata{}, procList) } diff --git a/io/printer_test_utils.go b/io/printer_test_utils.go deleted file mode 100644 index 186be291..00000000 --- a/io/printer_test_utils.go +++ /dev/null @@ -1,17 +0,0 @@ -package io - -var originalPrinter Printer = nil - -func SetupMockPrinter(mockPrinter Printer) { - if originalPrinter == nil { - originalPrinter = printerInstance - } - printerInstance = mockPrinter -} - -func ResetPrinter() { - if originalPrinter != nil { - printerInstance = originalPrinter - originalPrinter = nil - } -} diff --git a/proctord/utility/utils.go b/proctord/utility/utils.go index 22774438..b88f9eca 100644 --- a/proctord/utility/utils.go +++ b/proctord/utility/utils.go @@ -16,7 +16,7 @@ const GenericNetworkErrorHeader = "Network Error!!!" const GenericResponseErrorHeader = "Server Error!!!" const ConfigProctorHostMissingError = "Config Error!!!\nMandatory config PROCTOR_HOST is missing in Proctor Config file." -const GenericTimeoutErrorBody = "Please check your Internet/VPN connection for connectivity to Proctor server." +const GenericTimeoutErrorBody = "Please check your Internet/VPN connection for connectivity to ProctorD." const JobSubmissionSuccess = "success" const JobSubmissionClientError = "client_error"