diff --git a/.github/codeql/codeql-config.yaml b/.github/codeql/codeql-config.yaml index c7c39668fd..f529b33120 100644 --- a/.github/codeql/codeql-config.yaml +++ b/.github/codeql/codeql-config.yaml @@ -4,7 +4,7 @@ queries: # - uses: github/codeql-go/ql/src@lgtm.com paths: - - '/cmd' - - '/hack' - - '/internal' - - '/pkg' + - "/cmd" + - "/hack" + - "/internal" + - "/pkg" diff --git a/internal/config/log.go b/internal/config/log.go index c8ddceb699..c120b91a36 100644 --- a/internal/config/log.go +++ b/internal/config/log.go @@ -17,12 +17,14 @@ // Package config providers configuration type and load configuration logic package config +// Logging represents Logging configuration. type Logging struct { Logger string `json:"logger" yaml:"logger"` Level string `json:"level" yaml:"level"` Format string `json:"format" yaml:"format"` } +// Bind returns Logging object whose every value is field value or envirionment value. func (l *Logging) Bind() *Logging { l.Logger = GetActualValue(l.Logger) l.Level = GetActualValue(l.Level) diff --git a/internal/config/log_test.go b/internal/config/log_test.go index c12b4d4b93..d36f8d2773 100644 --- a/internal/config/log_test.go +++ b/internal/config/log_test.go @@ -18,6 +18,7 @@ package config import ( + "os" "reflect" "testing" @@ -48,35 +49,52 @@ func TestLogging_Bind(t *testing.T) { return nil } tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - fields: fields { - Logger: "", - Level: "", - Format: "", - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - fields: fields { - Logger: "", - Level: "", - Format: "", - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ + { + name: "returns Logging when all fields contain no prefix/suffix symbol", + fields: fields{ + Logger: "logger", + Level: "info", + Format: "json", + }, + want: want{ + want: &Logging{ + Logger: "logger", + Level: "info", + Format: "json", + }, + }, + }, + { + name: "returns Logging with environment variable when it contains `_` prefix and suffix", + fields: fields{ + Logger: "_logger_", + Level: "_level_", + Format: "_format_", + }, + beforeFunc: func() { + _ = os.Setenv("logger", "glg") + _ = os.Setenv("level", "info") + _ = os.Setenv("format", "json") + }, + afterFunc: func() { + _ = os.Unsetenv("logger") + _ = os.Unsetenv("level") + _ = os.Unsetenv("format") + }, + want: want{ + want: &Logging{ + Logger: "glg", + Level: "info", + Format: "json", + }, + }, + }, + { + name: "returns Logging when all fields are empty", + want: want{ + want: new(Logging), + }, + }, } for _, test := range tests {