test: Phase 3 — boost main package coverage to 82.8%#24
Conversation
| assert.NoError(t, err) | ||
| assert.NoError(t, MockLoad(m)) | ||
|
|
||
| query := MockQuery1() |
There was a problem hiding this comment.
**Misleading setup: MockLoad(m) here loads data into m's internal DB, but clients was created from a separate newClients(t.TempDir()) with a different SQLite file. The loaded data is never visible to clients.
Since BuildSQL only generates a SQL string and never executes, the test still passes — but the MockLoad(m) call is dead weight that implies a dependency that does not exist. Consider either:
- Removing
MockLoad(m)(and the manager entirely), or - Simplifying to
sql, err := m.BuildSQL(query)directly (which also testsManager.BuildSQL— though that is covered byTestManager_BuildSQLbelow).
|
|
||
| query := &types.Query{ | ||
| DataSetName: mockWikiStatDataSet, | ||
| Sql: "SELECT 1", |
There was a problem hiding this comment.
Variable naming + weak assertion. The variable sql is a types.Clause, not a SQL string — calling it sql is confusing. Suggest renaming to clause.
More importantly, assert.NotNil(t, clause) does not verify that the direct-SQL path actually preserved query.Sql. Since the whole point of this test is to cover the query.Sql != "" branch, consider also asserting that the clause carries the original SQL:
clause, err := dict.Translate(query)
assert.NoError(t, err)
assert.NotNil(t, clause)
// verify the direct-SQL path preserved the raw SQL
if sc, ok := clause.(*types.SqlClause); ok {
assert.Equal(t, "SELECT 1", sc.Sql)
} else {
t.Errorf("expected *types.SqlClause, got %T", clause)
}This makes the test actually exercise what it claims to test.
AWaterColorPen
left a comment
There was a problem hiding this comment.
Good coverage boost — all seven target code paths are now reached, and the helper functions (newDictionary, newFileAdapter) are clean and well-scoped.
Two things to fix before merging:
-
TestClients_BuildSQL—MockLoad(m)is dead code here (loads data into manager's DB, not the separateclientsinstance). Remove it, or simplify by callingm.BuildSQL(query)directly. -
TestNewTranslator_DirectSQL— the result variable is namedsqlbut holds atypes.Clause; and the assertion (NotNil) does not verify the direct-SQL path actually preserved the raw SQL string. Please rename and add a type assertion to checkclause.(*types.SqlClause).Sql == "SELECT 1".
Everything else looks correct: TestDBOption_NewDB_UnsupportedType correctly targets the default branch in getDialect, the SetLogger smoke tests are sufficient given the trivial implementations, and TestFileAdapter_GetMetricsBySource/GetDimensionsBySource appropriately test both the happy path and the empty-result path.
…L, strengthen TestNewTranslator_DirectSQL assertion
|
Both review items addressed in commit 56d672f:
All tests pass at 82.8% coverage. |
Summary
Phase 3 first step: push the main package test coverage from 79.1% to 82.8% (goal: 80%+).
What changed
Added
coverage_boost_test.gowith targeted tests for previously uncovered functions:Clients.SetLoggerclient.goClients.BuildSQLclient.goManager.SetLoggermanager.goManager.BuildSQLmanager.goNewTranslator(direct-SQL path)dictionary_translator.goFileAdapter.GetMetricsBySourcedictionary_adapter.goFileAdapter.GetDimensionsBySourcedictionary_adapter.goDBOption.NewDBunsupported-type error pathdatabase.goCoverage before / after
Notes