(t *testing.T)
| 232 | } |
| 233 | |
| 234 | func TestCheckDeclaredSubtype(t *testing.T) { |
| 235 | allowlist := map[string]struct{}{ |
| 236 | "missing_scope": {}, |
| 237 | "rate_limit": {}, |
| 238 | "invalid_parameters": {}, |
| 239 | } |
| 240 | cases := []struct { |
| 241 | name string |
| 242 | src string |
| 243 | wantAction Action |
| 244 | wantInMsg string |
| 245 | }{ |
| 246 | { |
| 247 | name: "named_const_selector_accepted", |
| 248 | src: `package x |
| 249 | import "github.com/larksuite/cli/errs" |
| 250 | var _ = struct{ Subtype errs.Subtype }{Subtype: errs.SubtypeMissingScope} |
| 251 | `, |
| 252 | wantAction: "", |
| 253 | }, |
| 254 | { |
| 255 | name: "literal_in_allowlist_accepted", |
| 256 | src: `package x |
| 257 | var _ = struct{ Subtype string }{Subtype: "missing_scope"} |
| 258 | `, |
| 259 | wantAction: "", |
| 260 | }, |
| 261 | { |
| 262 | name: "undeclared_literal_rejected", |
| 263 | src: `package x |
| 264 | var _ = struct{ Subtype string }{Subtype: "my_custom_thing"} |
| 265 | `, |
| 266 | wantAction: ActionReject, |
| 267 | wantInMsg: "my_custom_thing", |
| 268 | }, |
| 269 | { |
| 270 | name: "undeclared_via_cast_rejected", |
| 271 | src: `package x |
| 272 | import "github.com/larksuite/cli/errs" |
| 273 | var _ = struct{ Subtype errs.Subtype }{Subtype: errs.Subtype("custom_value")} |
| 274 | `, |
| 275 | wantAction: ActionReject, |
| 276 | wantInMsg: "custom_value", |
| 277 | }, |
| 278 | { |
| 279 | name: "ad_hoc_does_not_fire_in_rule_e", |
| 280 | src: `package x |
| 281 | var _ = struct{ Subtype string }{Subtype: "ad_hoc_thing"} |
| 282 | `, |
| 283 | // CheckDeclaredSubtype hands ad_hoc_* off to CheckAdHocSubtype — returns no E-class violation. |
| 284 | wantAction: "", |
| 285 | }, |
| 286 | { |
| 287 | name: "dynamic_local_var_warns", |
| 288 | src: `package x |
| 289 | var loc = "x" |
| 290 | var _ = struct{ Subtype string }{Subtype: loc} |
| 291 | `, |
nothing calls this directly
no test coverage detected