{"record":{"id":"82b8fea9e5a07f25","repo":"grafana/k6","slug":"no-value-82b8fe","errorCode":null,"errorMessage":"no value","messagePattern":"no value","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/secretsource/mock/mock.go","lineNumber":48,"sourceCode":"// NewMockSecretSource returns a new secret source mock with the provided name and map of secrets\nfunc NewMockSecretSource(secrets map[string]string) secretsource.Source {\n\treturn &mockSecretSource{\n\t\tinternal: secrets,\n\t}\n}\n\ntype mockSecretSource struct {\n\tinternal map[string]string\n}\n\nfunc (mss *mockSecretSource) Description() string {\n\treturn \"this is a mock secret source\"\n}\n\nfunc (mss *mockSecretSource) Get(key string) (string, error) {\n\tv, ok := mss.internal[key]\n\tif !ok {\n\t\treturn \"\", errors.New(\"no value\")\n\t}\n\treturn v, nil\n}\n","sourceCodeStart":30,"sourceCodeEnd":52,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/secretsource/mock/mock.go#L30-L52","documentation":"Identical lookup semantics to the file secret source, but returned by the built-in mock secret source used in k6's own tests. mockSecretSource serves a fixed internal map; requesting any key not in that map returns 'no value'. Seeing it in production means a test double leaked into a real run or an embedding is reusing k6's test fixtures.","triggerScenarios":"Unit/integration tests of secret-source plumbing that call Get() on the mock with an unseeded key; embedding k6 and accidentally importing internal/secretsource/mock in non-test code; test helpers that share one mock instance across cases where earlier tests seed different keys.","commonSituations":"Writing new tests for secret sources and forgetting to seed the map; refactoring tests so a previously-seeded key is now cleared; asserting on the error string ('no value') which couples tests to the message.","solutions":["Seed the mock with the key before Get: mock.New(map[string]string{\"api_key\": \"x\"}) or the package's equivalent constructor","Prefer errors.Is / sentinel-error checks over matching the raw 'no value' string in test assertions","Keep internal/secretsource/mock imports confined to _test.go files; audit embedders that ship it in production binaries"],"exampleFix":"// before\nsrc := mock.New(map[string]string{})\n_, err := src.Get(\"api_key\") // err: no value\n\n// after\nsrc := mock.New(map[string]string{\"api_key\": \"test-value\"})\nv, err := src.Get(\"api_key\")","handlingStrategy":"validation","validationCode":"// In tests: seed every key the test will read before calling Get.\nrequired := []string{\"api_key\", \"db_password\"}\nfor _, k := range required {\n    if _, ok := seeded[k]; !ok {\n        t.Fatalf(\"mock secret source not seeded with %q\", k)\n    }\n}","typeGuard":null,"tryCatchPattern":"In Go tests, call Get and assert on ok/err separately; use require.NoError with a message naming the key, and treat 'no value' as a fixture bug, not a runtime condition.","preventionTips":["Build the mock from one map literal inside each test case instead of mutating a shared instance","Assert on sentinel errors (errors.Is) rather than the 'no value' string","Keep mock imports test-only; grep production builds for internal/secretsource/mock"],"tags":["k6","secrets","mock","testing","key-not-found"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}