gofr-dev / gofr-dev/gofr

Raise submodule test coverage: 13 files at 0% with generated mocks already in place

Open
#4,200 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
20.9k
Forks
1.8k
Avg merge
5d 18h
Merged PRs (30d)
39

Description

**Is your feature request related to a problem? Please describe.**

Once #3866 / #3940 land, the datasource and metrics-exporter submodules are part of the published
coverage figure for the first time — and they dominate it. In the merged profile from
[run 34580707916](https://github.com/gofr-dev/gofr/actions/runs/34580707916) the submodules
contribute **6,009 of 8,770 statements (69%)** and sit at **74.7%**, so submodule coverage is now
the main lever on the repo-wide number.

The cheap part of that gap is unusually cheap: **13 files are at exactly 0%**, and most of the
modules they live in *already ship* `interface.go` + generated `mock_*.go` (gomock). The seams
exist; nothing is testing through them. No Docker, no live services, no new abstractions — just
table-driven tests against mocks that are already committed.

**Describe the solution you'd like**

Cover the files below. Each is independent, so this splits cleanly across contributors and makes a
good first issue set. Statement counts are from the merged profile, with `mock_*.go` excluded (the
same rule the merge step applies).

| file | stmts (all uncovered) | mocks available | notes |
|---|---|---|---|
| `pkg/gofr/datasource/file/sftp/file.go` | 59 | ✅ `mock_interface.go` | biggest single win |
| `pkg/gofr/datasource/couchbase/wrappers.go` | 35 | ✅ `mock_interfaces.go` | thin driver wrappers |
| `pkg/gofr/datasource/surrealdb/utils.go` | 17 | n/a | pure funcs: `clean`, `PrettyPrint`, `isAdministrativeOperation`, `isCustomNil` — zero deps |
| `pkg/gofr/datasource/pubsub/nats/pubsub_wrapper.go` | 17 | ✅ | |
| `pkg/gofr/datasource/influxdb/internal.go` | 15 | ✅ | |
| `pkg/gofr/datasource/couchbase/logger.go` | 11 | ✅ `mock_logger.go` | |
| `pkg/gofr/datasource/influxdb/logger.go` | 10 | ✅ | |
| `pkg/gofr/datasource/kv-store/nats/logger.go` | 8 | ✅ `mock_logger.go` | `PrettyPrint` |
| `pkg/gofr/datasource/pubsub/eventhub/message.go` | 7 | ✅ `mock_logger.go` | `Commit` |
| `pkg/gofr/datasource/dgraph/metrics.go` | 7 | ✅ `mock_metrics.go` | |
| `pkg/gofr/datasource/surrealdb/wrapper.go` | 5 | ✅ `mock_interface.go` | `NewDBWrapper`, `Use`, `SignIn`, `Info`, `GetDB` |
| `pkg/gofr/datasource/solr/logger.go` | 4 | ✅ `mock_logger.go` | |
| `pkg/gofr/datasource/kv-store/dynamodb/logger.go` | 1 | ✅ | |

**196 statements**, all currently unexecuted.

Tests should follow the repo convention: one test function per method, table-driven over a
`[]struct` of cases.

**Describe alternatives you've considered**

The same coverage could be reached with testcontainers-backed integration tests, but that is a much
larger change to CI runtime and flakiness for the same statements — these files are wrappers,
loggers and pure helpers whose behaviour is fully observable through the existing mocks.

**Additional context**

Where the rest of the submodule gap lives, for anyone who wants the larger pieces (these need new
tests or a seam, not just mocks — worth separate issues):

| module | coverage | uncovered stmts | effect on the repo-wide figure if taken to 90% |
|---|---|---|---|
| `datasource/surrealdb` | 24.8% | 228 | +2.25pp |
| `datasource/pubsub/eventhub` | 40.5% | 169 | +1.60pp |
| `datasource/mongo` | 34.5% | 97 | +0.94pp — **already fixed by dropping `-short`** in #4201 |
| `datasource/couchbase` | 62.4% | 86 | +0.72pp |
| `datasource/file/sftp` | 54.2% | 77 | +0.69pp |
| `datasource/influxdb` | 62.0% | 78 | +0.66pp |
| `datasource/kv-store/nats` | 45.9% | 53 | +0.49pp |

Two structural notes found while measuring:

1. **`surrealdb` needs one seam before it can move.** `newDB` (`surrealdb.go:89`) is called directly
inside `Connect`, so `Connect`, `connectToDatabase`, `setupNamespaceAndDatabase`, `signIn`,
`authenticateCredentials` and `HealthCheck` are all unreachable from a test. Making `newDB` a
package-level var (or a `Client` field) that tests swap for the existing `MockDB` unlocks all of
them at once.

2. **The `pkg/gofr` half of the figure has its own denominator problem, unrelated to this issue.**
The PKG job runs `-coverpkg=./pkg/gofr`, so the merged profile contains only the 29 top-level
`pkg/gofr/*.go` files (2,290 statements). Everything under `pkg/gofr/http`, `container`,
`logging`, `service`, `cmd` and the in-repo datasources is absent from the published number
entirely. That is the same class of gap #3866 fixed for submodules, one level up, and deserves
its own issue.

Contributor guide

Open the contributing guide

Research direction

Choose one of the listed zero-coverage files, such as pkg/gofr/datasource/file/sftp/file.go or pkg/gofr/datasource/surrealdb/utils.go. Read the target file with its existing interface and generated mock, then run the package's current tests. Add one table-driven test function per method using the available mocks or pure inputs, and confirm the target statements are covered without Docker or live services.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, testing-qa
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.