Fix incorrect attribute conversion
This commit is contained in:
		
							parent
							
								
									6bc66975db
								
							
						
					
					
						commit
						9374108288
					
				
					 2 changed files with 30 additions and 5 deletions
				
			
		|  | @ -43,11 +43,7 @@ func pmax(c echo.Context) error { | |||
| 	if len(attr) < 2 { | ||||
| 		return c.NoContent(400) | ||||
| 	} | ||||
| 	if len(attr) == 2 { | ||||
| 		attr = strings.ToUpper(attr[:2]) | ||||
| 	} else { | ||||
| 		attr = strings.ToUpper(attr[:2]) + strings.ToLower(attr[2:]) | ||||
| 	} | ||||
| 	attr = convertAttribute(attr) | ||||
| 
 | ||||
| 	date, err := time.Parse(time.RFC3339, c.Param(`date`)) | ||||
| 	if err != nil { | ||||
|  | @ -61,3 +57,12 @@ func pmax(c echo.Context) error { | |||
| 
 | ||||
| 	return c.JSON(200, data) | ||||
| } | ||||
| 
 | ||||
| func convertAttribute(attr string) string { | ||||
| 	attr = strings.ToUpper(attr[:1]) + strings.ToLower(attr[1:]) | ||||
| 
 | ||||
| 	attr = strings.Replace(attr, `gem`, `Gem`, -1) | ||||
| 	attr = strings.Replace(attr, `max`, `Max`, -1) | ||||
| 
 | ||||
| 	return attr | ||||
| } | ||||
|  |  | |||
							
								
								
									
										20
									
								
								server/main_test.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								server/main_test.go
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,20 @@ | |||
| package main | ||||
| 
 | ||||
| import ( | ||||
| 	"testing" | ||||
| 
 | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
| 
 | ||||
| func TestConvertAttribute(t *testing.T) { | ||||
| 	var data = map[string]string{ | ||||
| 		`cgem`: `CGem`, | ||||
| 		`ep`:   `Ep`, | ||||
| 		`PMAX`: `PMax`, | ||||
| 		`Test`: `Test`, | ||||
| 	} | ||||
| 
 | ||||
| 	for in, expected := range data { | ||||
| 		assert.Equal(t, expected, convertAttribute(in)) | ||||
| 	} | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue