-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): add Validators to ExportedConfigs and "config verify" c…
…ommand. (#154) * feat: add verification command * test: pass tests * test: fix failed tests * feat: support validators * test: add integration test * feat: add default config validation * fix: optimize test coverage * fix: optimize test coverage * fix: optimize test coverage * fix: json init issue * fix: json init issue * fix: remove version in config
- Loading branch information
Showing
18 changed files
with
618 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ core.iml | |
.idea/* | ||
/.idea/ | ||
.env | ||
config/testdata/module_test_partial.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package config_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/DoNewsCode/core" | ||
"github.com/DoNewsCode/core/config" | ||
"github.com/DoNewsCode/core/di" | ||
) | ||
|
||
func provideConfig() configOut { | ||
return configOut{ | ||
Config: []config.ExportedConfig{{ | ||
Validate: func(data map[string]interface{}) error { | ||
return errors.New("bad config") | ||
}, | ||
}}, | ||
} | ||
} | ||
|
||
type configOut struct { | ||
di.Out | ||
|
||
Config []config.ExportedConfig `group:"config,flatten"` | ||
} | ||
|
||
func Test_integration(t *testing.T) { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
return | ||
} | ||
t.Errorf("test should panic. the config is not valid.") | ||
}() | ||
c := core.Default() | ||
c.Provide(di.Deps{ | ||
provideConfig, | ||
}) | ||
c.AddModuleFunc(config.New) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.