microsoft / microsoft/mssql-rs
Add capability-based gating for ODBC e2e tests (mssql-odbc)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 53
- Forks
- 14
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 137
Description
Problem statement
The ODBC e2e DriverConnectLiveTest fixture gates every live test on ODBCTestConfig::HasConnection(), which is true whenever any connection method is configured (ODBC_TEST_CONNSTR, ODBC_TEST_DSN, or ODBC_TEST_SERVER). Most tests are fine with "any connection string that authenticates."
But some tests have stronger requirements. The connection-string parser-parity tests (MalformedTokenReturnsSuccessWithInfo, ConnectionStringParserParityBehaviors) assemble their own login strings from cfg.Server()/Uid()/Pwd() and deliberately corrupt individual auth tokens. In environments configured via ODBC_TEST_CONNSTR, a DSN, or integrated auth, Uid()/Pwd() are legitimately empty, so these tests would build broken empty-credential strings and fail even though the suite is configured correctly.
A tactical guard was added in PR #107 (ODBCTestConfig::HasSqlAuth() + GTEST_SKIP) to stop the spurious failures. This issue tracks the proper design: a small capability model so tests can declare what they need instead of hand-checking individual fields.
Proposed solution
Introduce a capability model on ODBCTestConfig and let each test declare its requirements:
enum class ODBCCap { SqlAuth, MutableDatabase, IntegratedAuth, Dsn, Encrypt };bool ODBCTestConfig::HasCapability(ODBCCap) const;SqlAuth=Server && Uid && Pwdall present- other values wired as best-effort predicates for future tests
- A one-line per-test skip helper (macro-backed, because
GTEST_SKIP()mustreturnfrom the test body to actually skip):ODBC_REQUIRE_CAP(ODBCCap::SqlAuth);at the top of a test
- Base-connection reuse so auth-neutral tests append to the configured connection instead of rebuilding it:
std::string ODBCTestUtils::BuildConnectionStringNarrow()delegating to the existingBuildConnectionString()(single source of truth), plus the existingSqlTStringoverload.
Then split the parser-parity tests:
- Auth-neutral cases (assert
01S00, connection still succeeds) append malformed tokens toBuildConnectionStringNarrow()and run against any working config — no capability gate. - Identity-corruption cases (assert
SQL_ERROR+28000, and first-wins duplicates) declareODBC_REQUIRE_CAP(ODBCCap::SqlAuth).
Note on first-wins: keep those UID-based under SqlAuth rather than converting to duplicate Database keys — BuildConnectionString() already emits a Database= key and the parser is first-wins, so an appended Database=bad;Database=good would lose to the base's existing Database and silently break the negative case.
Affected crate
Not sure / Multiple
Alternatives considered
- Keep the tactical
HasSqlAuth()+ inlineGTEST_SKIP(current state in PR #107): works, but every future special-requirement test re-implements its own field checks; doesn't scale. - A dedicated
SqlAuthLiveTestfixture whoseSetUp()skips unless SQL auth is present: reasonable, but a capability enum is more flexible when a test needs a combination of capabilities and keeps the requirement visible at the call site.
Additional context
Tactical fix commit: f457cff on saurabh500-odbc-connstr-parser (PR #107). The parity tests live in mssql-odbc/tests/e2e/tests/driver_connect_test.cpp; the fixture/config are in mssql-odbc/tests/e2e/include/odbc_test_fixture.h and lib/odbc_test_config.cpp; the base builder is ODBCTestUtils::BuildConnectionString() in lib/odbc_test_utils.cpp.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read mssql-odbc/tests/e2e/tests/driver_connect_test.cpp, mssql-odbc/tests/e2e/include/odbc_test_fixture.h, lib/odbc_test_config.cpp, and lib/odbc_test_utils.cpp, starting with the existing HasSqlAuth guard and connection-string builder. Add the capability checks and reuse the base connection string, then split the parser-parity cases so auth-neutral tests run with any configured connection and identity-corruption cases require SqlAuth.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, sql
- Domain
- databases, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100