@@ -87,7 +87,15 @@ func DefaultDeepConfiguration() *DeepConfig {
8787}
8888
8989func (cfg * DeepConfig ) Validate () error {
90- return nil
90+ // Validate Embedded Structs
91+ err := ValidateEmbedded (cfg )
92+ if err != nil {
93+ return err
94+ }
95+
96+ return validation .ValidateStruct (cfg ,
97+ validation .Field (& cfg .TestConfigDeep , validation .Required ),
98+ )
9199}
92100
93101func (cfg * ConfigurationTest ) Validate () error {
@@ -121,8 +129,18 @@ func TestErrorFormatting(t *testing.T) {
121129 cfg := DefaultConfiguration ()
122130 err := cfg .Validate ()
123131 require .Error (t , err )
132+
124133 errortest .AssertError (t , err , commonerrors .ErrInvalid )
125- assert .Contains (t , err .Error (), "invalid: structure failed validation: (TestConfig->db) [DUMMYCONFIG] cannot be blank" )
134+ assert .Contains (t , err .Error (), "invalid: structure failed validation: (TestConfig->db) [DUMMYCONFIG_DB] cannot be blank" )
135+ }
136+
137+ func TestDeepErrorFormatting (t * testing.T ) {
138+ cfg := DefaultDeepConfiguration ()
139+ err := cfg .Validate ()
140+ require .Error (t , err )
141+
142+ errortest .AssertError (t , err , commonerrors .ErrInvalid )
143+ assert .Contains (t , err .Error (), "invalid: structure failed validation: (TestConfigDeep->TestConfig->db) [DEEP_CONFIG_DUMMYCONFIG_DB] cannot be blank" )
126144}
127145
128146func TestServiceConfigurationLoad (t * testing.T ) {
@@ -133,6 +151,9 @@ func TestServiceConfigurationLoad(t *testing.T) {
133151 err := Load ("test" , configTest , defaults )
134152 // Some required values are missing.
135153 require .Error (t , err )
154+
155+ assert .ErrorContains (t , err , "(TestConfig->db) [TEST_DUMMYCONFIG_DB] cannot be blank" )
156+
136157 errortest .RequireError (t , err , commonerrors .ErrInvalid )
137158 errortest .RequireError (t , configTest .Validate (), commonerrors .ErrInvalid )
138159
0 commit comments