@@ -82,6 +82,19 @@ func TestLoadConfig(t *testing.T) {
8282 }
8383}
8484
85+ func TestLoadConfigBadRoot (t * testing.T ) {
86+ t .Chdir (t .TempDir ())
87+ err := os .WriteFile (configName , []byte ("bad-toml: [ a, 1, " ), 0644 )
88+ if err != nil {
89+ t .Fatal (err )
90+ }
91+ source := map [string ]string {"root1" : "rv1" }
92+ codec := map [string ]string {"root2" : "rv2" }
93+ if _ , err = LoadConfig ("root-language" , source , codec ); err == nil {
94+ t .Errorf ("expected an error when loading a missing file" )
95+ }
96+ }
97+
8598func TestLoadRootConfigOnlyGeneral (t * testing.T ) {
8699 tempFile , err := os .CreateTemp (t .TempDir (), "root-config-" )
87100 if err != nil {
@@ -247,6 +260,39 @@ func TestMergeLocalForDocumentationOverrides(t *testing.T) {
247260 }
248261}
249262
263+ func TestMergeConfigAndFileBadRead (t * testing.T ) {
264+ root := Config {
265+ General : GeneralConfig {
266+ Language : "root-language" ,
267+ SpecificationFormat : "root-specification-format" ,
268+ IgnoredDirectories : []string {"a" , "b" },
269+ },
270+ }
271+
272+ filename := path .Join (t .TempDir (), "file-does-not-exist" )
273+ if _ , err := MergeConfigAndFile (& root , filename ); err == nil {
274+ t .Error ("expected read error with missing file" )
275+ }
276+ }
277+
278+ func TestMergeConfigAndFileBadContent (t * testing.T ) {
279+ root := Config {
280+ General : GeneralConfig {
281+ Language : "root-language" ,
282+ SpecificationFormat : "root-specification-format" ,
283+ IgnoredDirectories : []string {"a" , "b" },
284+ },
285+ }
286+
287+ filename := path .Join (t .TempDir (), configName )
288+ if err := os .WriteFile (filename , []byte ("bad-toml = [ 1, 2" ), 0644 ); err != nil {
289+ t .Fatal (err )
290+ }
291+ if _ , err := MergeConfigAndFile (& root , filename ); err == nil {
292+ t .Error ("expected read error with bad contents" )
293+ }
294+ }
295+
250296func TestMergeIgnoreRootSourceAndServiceConfig (t * testing.T ) {
251297 root := Config {
252298 General : GeneralConfig {
0 commit comments