{"id":22301330,"url":"https://github.com/kasonbraley/marker","last_synced_at":"2025-03-25T23:42:02.432Z","repository":{"id":246858547,"uuid":"824303694","full_name":"KasonBraley/marker","owner":"KasonBraley","description":"Traceable test coverage marks for Go","archived":false,"fork":false,"pushed_at":"2025-02-12T03:31:13.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-12T04:29:35.529Z","etag":null,"topics":["go","golang","logging","slog","testing"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/KasonBraley/marker","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KasonBraley.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-04T20:17:51.000Z","updated_at":"2025-02-12T03:32:21.000Z","dependencies_parsed_at":"2024-07-05T15:17:59.649Z","dependency_job_id":null,"html_url":"https://github.com/KasonBraley/marker","commit_stats":null,"previous_names":["kasonbraley/marker"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KasonBraley%2Fmarker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KasonBraley%2Fmarker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KasonBraley%2Fmarker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KasonBraley%2Fmarker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KasonBraley","download_url":"https://codeload.github.com/KasonBraley/marker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245563044,"owners_count":20635907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","logging","slog","testing"],"created_at":"2024-12-03T18:19:52.505Z","updated_at":"2025-03-25T23:42:02.405Z","avatar_url":"https://github.com/KasonBraley.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Marker\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/KasonBraley/marker.svg)](https://pkg.go.dev/github.com/KasonBraley/marker)\n\nThis package provides a [slog.Handler](https://pkg.go.dev/log/slog#Handler) and an associated API for\nimplementing explicit code coverage marks for _linking_ source code and tests together.\n\nIn production code, you use your logger as normal, and can use it to say \"this should be covered by a test\".\nIn test code, you can then assert that a _specific_ test covers a specific log line.\n\nThe purpose of this is to help with test maintenance over time in larger projects. Large projects\noften have a lot of tests. Finding the tests for a specific piece of code, and vice versa, can be\na challenge. This package provides a simple solution to that problem by leveraging your existing\nlogger, and simply enabling the use of `grep` to search for a corresponding test. For example, if\nyou see `logger.Debug(\"request sent, waiting on response\")` in the code, you can grep for that log\nmessage and immediately find the test that goes with that code path.\n\nThe blog post that inspired this package goes over this testing technique and why it's useful in much\nmore detail. https://ferrous-systems.com/blog/coverage-marks/\n\nThis is not for \"coverage\". Coverage is the answer to the question \"Is this tested?\".\nMarks answer \"Why does this code need to exist?\".\n\nInspired by:\n\n- https://ferrous-systems.com/blog/coverage-marks/\n- https://en.wikipedia.org/wiki/Requirements_traceability\n\nImplementations of this concept in other languages:\n\n- [Rust](https://crates.io/crates/cov-mark)\n\n##### Example:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"io\"\n    \"log/slog\"\n\n    \"github.com/KasonBraley/marker\"\n)\n\nfunc main() {\n    run()\n}\n\nfunc run() {\n    logger := slog.New(marker.NewHandler(slog.NewTextHandler(io.Discard, nil)))\n    svc := newService(logger)\n    svc.isEven(2)\n}\n\ntype service struct {\n    logger *slog.Logger\n}\n\nfunc newService(logger *slog.Logger) *service {\n    return \u0026service{logger: logger}\n}\n\nfunc (s *service) isEven(x int) {\n    if x%2 == 0 {\n        s.logger.Info(fmt.Sprintf(\"x is even (x=%v)\", x))\n    }\n    s.logger.Info(fmt.Sprintf(\"x is odd (x=%v)\", x))\n}\n```\n\nCorresponding test:\n\n```go\nfunc TestIsEven(t *testing.T) {\n    svc := newService()\n\n    t.Run(\"even\", func(t *testing.T) {\n        mark := marker.Check(\"x is even\")\n        svc.isEven(2)\n        if err := mark.ExpectHit(); err != nil {\n            t.Error(err)\n        }\n    })\n\n    t.Run(\"odd\", func(t *testing.T) {\n        mark := marker.Check(\"x is even\") // If we change this to \"x is odd\", it will pass.\n        svc.isEven(3) // Odd number passed to show that we don't hit the expected mark.\n        if err := mark.ExpectHit(); err != nil {\n            t.Error(err) // The error `mark \"x is even\" not hit` is returned.\n        }\n    })\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkasonbraley%2Fmarker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkasonbraley%2Fmarker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkasonbraley%2Fmarker/lists"}