Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added internal/config/log test #530

Merged
merged 6 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/codeql/codeql-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ queries:
# - uses: github/codeql-go/ql/[email protected]

paths:
- '/cmd'
- '/hack'
- '/internal'
- '/pkg'
- "/cmd"
- "/hack"
- "/internal"
- "/pkg"
2 changes: 2 additions & 0 deletions internal/config/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
76 changes: 47 additions & 29 deletions internal/config/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package config

import (
"os"
"reflect"
"testing"

Expand Down Expand Up @@ -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 {
Expand Down