fix(core/config/xml): prompt error when config format is incorrect
This commit is contained in:
		
							parent
							
								
									56282466bc
								
							
						
					
					
						commit
						8bfee444fd
					
				| @ -70,7 +70,17 @@ func (xc *Config) ParseData(data []byte) (config.Configer, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	x.data = config.ExpandValueEnvForMap(d["config"].(map[string]interface{})) | 	v := d["config"] | ||||||
|  | 	if v == nil { | ||||||
|  | 		return nil, fmt.Errorf("xml parse should incluce in <config></config> tags") | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	confVal, ok := v.(map[string]interface{}) | ||||||
|  | 	if !ok { | ||||||
|  | 		return nil, fmt.Errorf("xml parse <config></config> tags should incluce sub tags") | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	x.data = config.ExpandValueEnvForMap(confVal) | ||||||
| 
 | 
 | ||||||
| 	return x, nil | 	return x, nil | ||||||
| } | } | ||||||
|  | |||||||
| @ -150,6 +150,25 @@ func TestXML(t *testing.T) { | |||||||
| 	assert.Equal(t, "MySection", sec.Name) | 	assert.Equal(t, "MySection", sec.Name) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func TestXMLMissConfig(t *testing.T) { | ||||||
|  | 	xmlcontext1 := ` | ||||||
|  | 	<?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | 	<appname>beeapi</appname> | ||||||
|  | 	` | ||||||
|  | 
 | ||||||
|  | 	c := &Config{} | ||||||
|  | 	_, err := c.ParseData([]byte(xmlcontext1)) | ||||||
|  | 	assert.Equal(t, "xml parse should incluce in <config></config> tags", err.Error()) | ||||||
|  | 
 | ||||||
|  | 	xmlcontext2 := ` | ||||||
|  | 	<?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | 	<config></config> | ||||||
|  | 	` | ||||||
|  | 
 | ||||||
|  | 	_, err = c.ParseData([]byte(xmlcontext2)) | ||||||
|  | 	assert.Equal(t, "xml parse <config></config> tags should incluce sub tags", err.Error()) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| type Section struct { | type Section struct { | ||||||
| 	Name string `xml:"name"` | 	Name string `xml:"name"` | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user