Resolves #45220 (one of several PRs to achieve removing "testing" package as dependency in production binary) ## Testing - [x] QA'd all new/changed functionality manually. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Switched many tests to use a dedicated MySQL test helper package and consolidated test-only utilities for datastore setup, cleanup, ad‑hoc SQL, certificate generation, and activity/aggregation helpers. * Added expanded test utilities for replication, DB connections and test data seeding to improve integration-test reliability. * **Chores** * No production behavior or user-facing APIs were changed. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/fleetdm/fleet/pull/45406) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
64 lines
2.0 KiB
Go
64 lines
2.0 KiB
Go
package mysql
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/config"
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
common_mysql "github.com/fleetdm/fleet/v4/server/platform/mysql"
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
// CheckAndModifyMysqlConfig is an exported wrapper around the package's
|
|
// internal config validator; used by mysqltest helpers. It must not be used
|
|
// from production code other than the existing mysql package internals.
|
|
func CheckAndModifyMysqlConfig(conf *config.MysqlConfig) error {
|
|
return checkAndModifyConfig(conf)
|
|
}
|
|
|
|
// TestPrimaryDB exposes the primary *sqlx.DB for use by test helpers in the
|
|
// mysqltest package. It must not be used from production code.
|
|
func (ds *Datastore) TestPrimaryDB() *sqlx.DB {
|
|
return ds.primary
|
|
}
|
|
|
|
// TestReplica returns the replica fleet.DBReader for use by test helpers.
|
|
// It must not be used from production code.
|
|
func (ds *Datastore) TestReplica() fleet.DBReader {
|
|
return ds.replica
|
|
}
|
|
|
|
// TestSetReplica overrides the replica for use by test helpers. It must not
|
|
// be used from production code.
|
|
func (ds *Datastore) TestSetReplica(r fleet.DBReader) {
|
|
ds.replica = r
|
|
}
|
|
|
|
// TestSetReadReplicaConfig overrides the read replica MySQL config for use
|
|
// by test helpers. It must not be used from production code.
|
|
func (ds *Datastore) TestSetReadReplicaConfig(cfg *common_mysql.MysqlConfig) {
|
|
ds.readReplicaConfig = cfg
|
|
}
|
|
|
|
// TestLogger returns the datastore's logger for use by test helpers.
|
|
func (ds *Datastore) TestLogger() *slog.Logger {
|
|
return ds.logger
|
|
}
|
|
|
|
// TestWriter returns the writer DB for use by test helpers.
|
|
func (ds *Datastore) TestWriter(ctx context.Context) *sqlx.DB {
|
|
return ds.writer(ctx)
|
|
}
|
|
|
|
// TestReader returns the reader DB for use by test helpers.
|
|
func (ds *Datastore) TestReader(ctx context.Context) fleet.DBReader {
|
|
return ds.reader(ctx)
|
|
}
|
|
|
|
// TestEncrypt encrypts data with the datastore's server private key for use
|
|
// by test helpers. It must not be used from production code.
|
|
func (ds *Datastore) TestEncrypt(data []byte) ([]byte, error) {
|
|
return encrypt(data, ds.serverPrivateKey)
|
|
}
|