Skip to content

test: repo lacks unit-test infrastructure; db/table/reconciler tests panic without a live MongoDB #122

Description

@Prabhjot-Sethi

Problem

The repo has no usable unit-test infrastructure for the db/ and table/ layers. Today go test ./table/... ./reconciler/... panics outright without a live MongoDB:

log.Panicf(...)
github.com/go-core-stack/core/reconciler.performMongoSetup()
    reconciler/reconciler_test.go:76
FAIL	github.com/go-core-stack/core/reconciler	30.011s
FAIL	github.com/go-core-stack/core/table	30.012s

This reproduces on main, so it is not a regression — it is a standing gap. errors/errors_test.go is currently the only package with tests that run unconditionally.

Why it matters now

This surfaced while reviewing #121, which introduces a new errors.Unavailable class and a isTransientMongoError / interpretMongoError classification path. The entire value of that change is correct classification, and there is currently no established place to assert it.

Notably, several of the affected functions are pure and need no MongoDB at all:

  • isTransientMongoError(err error) bool
  • interpretMongoError(err error) error
  • errors.IsUnavailable / errors.GetErrCode
  • the GetErrCode(err) != Unknown branch in CachedTable.DBFind

They can be driven entirely with fabricated errors. The blocker is not that these are untestable — it is that there is no pattern to follow and no way to run the surrounding package tests locally.

Proposal

  1. Make the db/table/reconciler package tests skip cleanly (t.Skip) when no MongoDB is reachable, instead of log.Panicf. That alone makes go test ./... usable.
  2. Establish a pattern for MongoDB-backed tests — either a testcontainers harness or a fake behind the existing collection interface.
  3. Add table-free unit tests for the pure error-classification helpers.

Item 1 is the cheap unblock and can land independently.

Notes

Deliberately scoped out of #121 — standing up test infra inside a behavior fix would bury the fix. Filing separately so #121 can land on its own merits.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions