From d2c550dd92715521a5b5d9252ded014467eef230 Mon Sep 17 00:00:00 2001 From: djeeno <29125616+djeeno@users.noreply.github.com> Date: Mon, 30 Nov 2020 18:39:11 +0900 Subject: [PATCH] Fix log (#20) --- main.go | 16 ++++++++-------- main_test.go | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index 34d7b28..cc70728 100644 --- a/main.go +++ b/main.go @@ -261,28 +261,28 @@ func readFile(path string) ([]byte, error) { return bytea, nil } -func getOptOrEnvOrDefault(optKey, optValue, envKey, defaultValue string) (string, error) { - if optKey == "" { - return "", fmt.Errorf("optKey is empty") +func getOptOrEnvOrDefault(optName, optValue, envName, defaultValue string) (string, error) { + if optName == "" { + return "", fmt.Errorf("optName is empty") } if optValue != "" { - log.Println("use option: " + optKey + "=" + optValue) + log.Println("use option value: -" + optName + "=" + optValue) return optValue, nil } - envValue := os.Getenv(envKey) + envValue := os.Getenv(envName) if envValue != "" { - log.Println("use env: " + envKey + "=" + envValue) + log.Println("use environment variable: " + envName + "=" + envValue) return envValue, nil } if defaultValue != "" { - log.Println("use default: " + optKey + "=" + defaultValue) + log.Println("use default option value: -" + optName + "=" + defaultValue) return defaultValue, nil } - return "", fmt.Errorf("set option -%s, or set environment variable %s", optKey, envKey) + return "", fmt.Errorf("set option -%s, or set environment variable %s", optName, envName) } func capitalizeInitial(s string) (capitalized string) { diff --git a/main_test.go b/main_test.go index c954c49..6b78f78 100644 --- a/main_test.go +++ b/main_test.go @@ -32,9 +32,9 @@ const ( testProbablyExistsPath = "go.mod" // getOptOrEnvOrDefault - testOptKey = "testOptKey" + testOptName = "test-opt-key" testOptValue = "testOptValue" - testEnvKey = "TEST_ENV_KEY" + testEnvName = "TEST_ENV_KEY" testEnvValue = "testEnvValue" testDefaultValue = "testDefaultValue" @@ -286,7 +286,7 @@ func Test_readFile_NG_2(t *testing.T) { } func Test_getOptOrEnvOrDefault_OK_1(t *testing.T) { - v, err := getOptOrEnvOrDefault(testOptKey, testOptValue, testEnvKey, testDefaultValue) + v, err := getOptOrEnvOrDefault(testOptName, testOptValue, testEnvName, testDefaultValue) if err != nil { t.Error(err) } @@ -295,24 +295,24 @@ func Test_getOptOrEnvOrDefault_OK_1(t *testing.T) { } } func Test_getOptOrEnvOrDefault_OK_2(t *testing.T) { - if err := os.Setenv(testEnvKey, testEnvValue); err != nil { + if err := os.Setenv(testEnvName, testEnvValue); err != nil { t.Error(err) } - v, err := getOptOrEnvOrDefault(testOptKey, testEmptyString, testEnvKey, testDefaultValue) + v, err := getOptOrEnvOrDefault(testOptName, testEmptyString, testEnvName, testDefaultValue) if err != nil { t.Error(err) } if v != testEnvValue { t.Error(err) } - if err := os.Unsetenv(testEnvKey); err != nil { + if err := os.Unsetenv(testEnvName); err != nil { t.Error(err) } } func Test_getOptOrEnvOrDefault_OK_3(t *testing.T) { - v, err := getOptOrEnvOrDefault(testOptKey, testEmptyString, testEnvKey, testDefaultValue) + v, err := getOptOrEnvOrDefault(testOptName, testEmptyString, testEnvName, testDefaultValue) if err != nil { t.Error(err) } @@ -332,7 +332,7 @@ func Test_getOptOrEnvOrDefault_NG_1(t *testing.T) { } func Test_getOptOrEnvOrDefault_NG_2(t *testing.T) { - v, err := getOptOrEnvOrDefault(testOptKey, testEmptyString, testEnvKey, testEmptyString) + v, err := getOptOrEnvOrDefault(testOptName, testEmptyString, testEnvName, testEmptyString) if err == nil { t.Error(err) }