Skip to content

Commit

Permalink
fix: rollback NewMongoREpository construct function to not be changed (
Browse files Browse the repository at this point in the history
  • Loading branch information
exu authored Feb 14, 2024
1 parent 3ef4598 commit 85899d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func main() {
db, err := storage.GetMongoDatabase(cfg.APIMongoDSN, cfg.APIMongoDB, cfg.APIMongoDBType, cfg.APIMongoAllowTLS, mongoSSLConfig)
ui.ExitOnError("Getting mongo database", err)
isDocDb := cfg.APIMongoDBType == storage.TypeDocDB
mongoResultsRepository := result.NewMongoRepository(db, logGrpcClient, cfg.APIMongoAllowDiskUse, isDocDb, features)
mongoResultsRepository := result.NewMongoRepository(db, cfg.APIMongoAllowDiskUse, isDocDb, result.WithFeatureFlags(features), result.WithLogsClient(logGrpcClient))
resultsRepository = mongoResultsRepository
testResultsRepository = testresult.NewMongoRepository(db, cfg.APIMongoAllowDiskUse, isDocDb)
configRepository = configrepository.NewMongoRepository(db)
Expand Down
18 changes: 14 additions & 4 deletions pkg/repository/result/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ const (
StepMaxCount = 100
)

func NewMongoRepository(db *mongo.Database, logGrpcClient logsclient.StreamGetter, allowDiskUse, isDocDb bool,
features featureflags.FeatureFlags, opts ...MongoRepositoryOpt) *MongoRepository {
// NewMongoRepository creates a new MongoRepository - used by other testkube components - use opts to extend the functionality
func NewMongoRepository(db *mongo.Database, allowDiskUse, isDocDb bool, opts ...MongoRepositoryOpt) *MongoRepository {
r := &MongoRepository{
db: db,
ResultsColl: db.Collection(CollectionResults),
SequencesColl: db.Collection(CollectionSequences),
OutputRepository: NewMongoOutputRepository(db),
logGrpcClient: logGrpcClient,
allowDiskUse: allowDiskUse,
isDocDb: isDocDb,
features: features,
log: log.DefaultLogger,
}

Expand Down Expand Up @@ -112,6 +110,18 @@ type MongoRepository struct {

type MongoRepositoryOpt func(*MongoRepository)

func WithLogsClient(client logsclient.StreamGetter) MongoRepositoryOpt {
return func(r *MongoRepository) {
r.logGrpcClient = client
}
}

func WithFeatureFlags(features featureflags.FeatureFlags) MongoRepositoryOpt {
return func(r *MongoRepository) {
r.features = features
}
}

func WithMongoRepositoryResultCollection(collection *mongo.Collection) MongoRepositoryOpt {
return func(r *MongoRepository) {
r.ResultsColl = collection
Expand Down

0 comments on commit 85899d0

Please sign in to comment.