mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +00:00 
			
		
		
		
	Refactor context flash msg and global variables (#33375)
1. add `GetSiteCookieFlashMessage` to help to parse flash message 2. clarify `handleRepoHomeFeed` logic 3. remove unnecessary global variables, use `sync.OnceValue` instead 4. add some tests for `IsUsableUsername` and `IsUsableRepoName`
This commit is contained in:
		| @@ -19,40 +19,40 @@ func getGlobPatternErrorString(pattern string) string { | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| var globValidationTestCases = []validationTestCase{ | ||||
| 	{ | ||||
| 		description: "Empty glob pattern", | ||||
| 		data: TestForm{ | ||||
| 			GlobPattern: "", | ||||
| 		}, | ||||
| 		expectedErrors: binding.Errors{}, | ||||
| 	}, | ||||
| 	{ | ||||
| 		description: "Valid glob", | ||||
| 		data: TestForm{ | ||||
| 			GlobPattern: "{master,release*}", | ||||
| 		}, | ||||
| 		expectedErrors: binding.Errors{}, | ||||
| 	}, | ||||
|  | ||||
| 	{ | ||||
| 		description: "Invalid glob", | ||||
| 		data: TestForm{ | ||||
| 			GlobPattern: "[a-", | ||||
| 		}, | ||||
| 		expectedErrors: binding.Errors{ | ||||
| 			binding.Error{ | ||||
| 				FieldNames:     []string{"GlobPattern"}, | ||||
| 				Classification: ErrGlobPattern, | ||||
| 				Message:        getGlobPatternErrorString("[a-"), | ||||
| 			}, | ||||
| 		}, | ||||
| 	}, | ||||
| } | ||||
|  | ||||
| func Test_GlobPatternValidation(t *testing.T) { | ||||
| 	AddBindingRules() | ||||
|  | ||||
| 	globValidationTestCases := []validationTestCase{ | ||||
| 		{ | ||||
| 			description: "Empty glob pattern", | ||||
| 			data: TestForm{ | ||||
| 				GlobPattern: "", | ||||
| 			}, | ||||
| 			expectedErrors: binding.Errors{}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			description: "Valid glob", | ||||
| 			data: TestForm{ | ||||
| 				GlobPattern: "{master,release*}", | ||||
| 			}, | ||||
| 			expectedErrors: binding.Errors{}, | ||||
| 		}, | ||||
|  | ||||
| 		{ | ||||
| 			description: "Invalid glob", | ||||
| 			data: TestForm{ | ||||
| 				GlobPattern: "[a-", | ||||
| 			}, | ||||
| 			expectedErrors: binding.Errors{ | ||||
| 				binding.Error{ | ||||
| 					FieldNames:     []string{"GlobPattern"}, | ||||
| 					Classification: ErrGlobPattern, | ||||
| 					Message:        getGlobPatternErrorString("[a-"), | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	for _, testCase := range globValidationTestCases { | ||||
| 		t.Run(testCase.description, func(t *testing.T) { | ||||
| 			performValidationTest(t, testCase) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 wxiaoguang
					wxiaoguang