Skip to content

Commit

Permalink
added internal/config/log test (#530)
Browse files Browse the repository at this point in the history
* ✅ added internal/config/log test

Signed-off-by: vankichi <[email protected]>

* 📝 add godoc

Signed-off-by: vankichi <[email protected]>

* ✅ update test name

Signed-off-by: vankichi <[email protected]>

* ♻️ fix

Signed-off-by: vankichi <[email protected]>

* ♻️ fix

Signed-off-by: vankichi <[email protected]>

* 🤖 Update license headers / Format go codes and yaml files

Signed-off-by: vdaas-ci <[email protected]>

Co-authored-by: vdaas-ci <[email protected]>
  • Loading branch information
vankichi and vdaas-ci authored Jul 1, 2020
1 parent f0fd5d9 commit 543898b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 33 deletions.
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

0 comments on commit 543898b

Please sign in to comment.