(t *testing.T)
| 148 | } |
| 149 | |
| 150 | func TestPatternMatches(t *testing.T) { |
| 151 | tsts := []struct { |
| 152 | Name string |
| 153 | Key string |
| 154 | Pattern string |
| 155 | EventJSON string |
| 156 | Want bool |
| 157 | }{ |
| 158 | {"empty", "", "", `{}`, false}, |
| 159 | |
| 160 | // Note that an empty pattern contains no wildcard characters, |
| 161 | // which implicitly means "*". |
| 162 | {"patternEmpty", "content", "", `{"content":{}}`, true}, |
| 163 | |
| 164 | {"literal", "content.creator", "acreator", `{"content":{"creator":"acreator"}}`, true}, |
| 165 | {"substring", "content.creator", "reat", `{"content":{"creator":"acreator"}}`, true}, |
| 166 | {"singlePattern", "content.creator", "acr?ator", `{"content":{"creator":"acreator"}}`, true}, |
| 167 | {"multiPattern", "content.creator", "a*ea*r", `{"content":{"creator":"acreator"}}`, true}, |
| 168 | {"patternNoSubstring", "content.creator", "r*t", `{"content":{"creator":"acreator"}}`, false}, |
| 169 | } |
| 170 | for _, tst := range tsts { |
| 171 | t.Run(tst.Name, func(t *testing.T) { |
| 172 | got, err := patternMatches(tst.Key, tst.Pattern, mustEventFromJSON(t, tst.EventJSON)) |
| 173 | if err != nil { |
| 174 | t.Fatalf("patternMatches failed: %v", err) |
| 175 | } |
| 176 | if got != tst.Want { |
| 177 | t.Errorf("patternMatches: got %v, want %v", got, tst.Want) |
| 178 | } |
| 179 | }) |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | func mustEventFromJSON(t *testing.T, json string) *gomatrixserverlib.Event { |
| 184 | ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(json), false, gomatrixserverlib.RoomVersionV7) |
nothing calls this directly
no test coverage detected