MCPcopy
hub / github.com/larksuite/cli / TestCheckDeclaredSubtype

Function TestCheckDeclaredSubtype

lint/errscontract/rules_test.go:234–325  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

232}
233
234func 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
249import "github.com/larksuite/cli/errs"
250var _ = struct{ Subtype errs.Subtype }{Subtype: errs.SubtypeMissingScope}
251`,
252 wantAction: "",
253 },
254 {
255 name: "literal_in_allowlist_accepted",
256 src: `package x
257var _ = struct{ Subtype string }{Subtype: "missing_scope"}
258`,
259 wantAction: "",
260 },
261 {
262 name: "undeclared_literal_rejected",
263 src: `package x
264var _ = 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
272import "github.com/larksuite/cli/errs"
273var _ = 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
281var _ = 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
289var loc = "x"
290var _ = struct{ Subtype string }{Subtype: loc}
291`,

Callers

nothing calls this directly

Calls 3

CheckDeclaredSubtypeFunction · 0.85
RunMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected