{"record":{"id":"f0d283120589eda2","repo":"hashicorp/nomad","slug":"unknown-checks-namespace-q","errorCode":null,"errorMessage":"unknown checks namespace: %q","messagePattern":"unknown checks namespace: %q","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/agent/consul/catalog_testing.go","lineNumber":395,"sourceCode":"\t\tif v.ServiceID == serviceID {\n\t\t\tdelete(c.checks[namespace], k)\n\t\t\tdelete(c.checkTTLs[namespace], k)\n\t\t}\n\t}\n\treturn nil\n}\n\n// UpdateTTLOpts implements AgentAPI\nfunc (c *MockAgent) UpdateTTLOpts(id string, output string, status string, q *api.QueryOptions) error {\n\tc.mu.Lock()\n\tdefer c.mu.Unlock()\n\n\tc.hits++\n\tnamespace := getNamespace(q)\n\n\tchecks, nsExists := c.checks[namespace]\n\tif !nsExists {\n\t\treturn fmt.Errorf(\"unknown checks namespace: %q\", namespace)\n\t}\n\n\tcheck, checkExists := checks[id]\n\tif !checkExists {\n\t\treturn fmt.Errorf(\"unknown check: %s/%s\", namespace, id)\n\t}\n\n\t// Flip initial status to passing\n\t// todo(shoenig) why not just set to the given status?\n\tcheck.Status = \"passing\"\n\tc.checkTTLs[namespace][id]++\n\n\treturn nil\n}\n\n// a convenience method for looking up a registered service by name\nfunc (c *MockAgent) lookupService(namespace, name string) []*api.AgentServiceRegistration {\n\tc.mu.Lock()","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/consul/catalog_testing.go#L377-L413","documentation":"UpdateTTLOpts is a MockAgent (test double for the Consul agent API) that simulates TTL check updates. It looks up the check by namespace (derived from QueryOptions or default) and returns this error when no check map exists for that namespace — i.e. the test fixture never registered any checks in that namespace.","triggerScenarios":"Calling MockAgent.UpdateTTLOpts with a QueryOptions whose Namespace resolves to a namespace not present in the mock's c.checks map — typically because the test never called the mock's check-registration/setup path for that namespace before updating its TTL.","commonSituations":"Unit tests passing an explicit namespace (Consul Enterprise namespaces) that the fixture didn't seed; tests copied from single-namespace setups and updated to use namespaces without updating fixture setup; getNamespace defaulting differently than expected when q is nil or has an empty namespace.","solutions":["Register the check in the mock under the expected namespace before calling UpdateTTLOpts (use the mock's check-registration method)","Make the test's QueryOptions.Namespace match the namespace used when seeding c.checks","If the default namespace was intended, pass nil QueryOptions or set the namespace the fixture seeded","Inspect getNamespace to confirm how the namespace is derived and align fixture and caller"],"exampleFix":"// before\nmock := NewMockAgent()\nmock.UpdateTTLOpts(\"check-1\", \"\", \"pass\", &api.QueryOptions{Namespace: \"team-a\"})\n\n// after\nmock := NewMockAgent()\nmock.AddCheck(\"check-1\", \"team-a\") // seed checks[\"team-a\"] first\nmock.UpdateTTLOpts(\"check-1\", \"\", \"pass\", &api.QueryOptions{Namespace: \"team-a\"})","handlingStrategy":"try-catch","validationCode":"func canUpdateTTL(mock *MockAgent, id string, q *api.QueryOptions) bool {\n\tns := getNamespace(q)\n\tmock.mu.Lock()\n\tdefer mock.mu.Unlock()\n\t_, nsOK := mock.checks[ns]\n\treturn nsOK\n}","typeGuard":"func namespaceExists(mock *MockAgent, q *api.QueryOptions) bool {\n\tns := getNamespace(q)\n\t_, ok := mock.checks[ns]\n\treturn ok\n}","tryCatchPattern":"if err := mock.UpdateTTLOpts(id, out, \"pass\", q); err != nil {\n\tif strings.HasPrefix(err.Error(), \"unknown checks namespace\") {\n\t\tt.Fatalf(\"fixture missing namespace; seed checks for %q before updating TTL\", getNamespace(q))\n\t}\n\tt.Fatal(err)\n}","preventionTips":["Seed the mock with checks for every namespace a test will touch","Keep QueryOptions.Namespace in tests consistent with the fixture's seeded namespace","Read getNamespace to know what nil/empty QueryOptions resolves to","When adding namespace support to a test, update fixture setup alongside callers"],"tags":["testing","consul","mock","namespace"],"backgroundTag":"unknown-namespace-in-mock","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}