Skip to content

Commit

Permalink
[Amir/Jenson] changes based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jenson committed Nov 8, 2018
1 parent cdd7541 commit 997b9bd
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 30 deletions.
3 changes: 1 addition & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
9 changes: 2 additions & 7 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"fmt"
"github.com/gojektech/proctor/io"
"io/ioutil"
"os"
"testing"
Expand Down Expand Up @@ -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: <host>\nEMAIL_ID: <email>\nACCESS_TOKEN: <access-token>\n", configFilePath)

_, err := LoadConfig()

assert.Equal(t, expectedMessage, err.Message)
mockPrinter.AssertExpectations(t)
}

func unsetEnvs() {
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions daemon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion daemon/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
17 changes: 0 additions & 17 deletions io/printer_test_utils.go

This file was deleted.

2 changes: 1 addition & 1 deletion proctord/utility/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 997b9bd

Please sign in to comment.