fix stringPatternMatch() and create test

This commit is contained in:
Yuli
2020-01-30 20:56:26 +02:00
parent 9c4aa393f9
commit dca199ce0c
2 changed files with 22 additions and 4 deletions

View File

@@ -36,6 +36,24 @@ func Test_AppNames(t *testing.T) {
}
func Test_stringPatternMatch(t *testing.T) {
goodJsons := []map[string]interface{}{
{"pattern":"*","name": "tom", "result": true},
{"pattern":"aa","name": "tom", "result": false},
{"pattern":"","name":"aa","result": false},
{"pattern":"test*","name":"123testabc", "result": false},
{"pattern":"test*","name":"testabc", "result": true},
{"pattern":"*test*","name":"test1", "result": true},
{"pattern":"*test","name":"123testabc", "result": false},
{"pattern":"*test","name":"123test", "result": true},
}
for _, value := range goodJsons {
if stringPatternMatch(value["pattern"].(string), value["name"].(string)) != value["result"].(bool) {
t.Fatalf("Failed in %s match %s\n", value["pattern"].(string), value["name"].(string))
}
}
}
func Test_getJSONPost(t *testing.T) {
goodJsons := []string{
`{"login":"abc","name": "tom", "pass": "mylittlepony", "admin": true}`,