@@ -72,27 +72,19 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
7272 indexStorageMode : MemoryOptimized ,
7373 }
7474
75- req := testcontainers.ContainerRequest {
76- Image : img ,
77- ExposedPorts : []string {MGMT_PORT + "/tcp" , MGMT_SSL_PORT + "/tcp" },
78- }
79-
80- genericContainerReq := testcontainers.GenericContainerRequest {
81- ContainerRequest : req ,
82- Started : true ,
75+ moduleOpts := []testcontainers.ContainerCustomizer {
76+ testcontainers .WithExposedPorts (MGMT_PORT + "/tcp" , MGMT_SSL_PORT + "/tcp" ),
8377 }
8478
79+ serviceCustomizers := make ([]testcontainers.ContainerCustomizer , 0 , len (initialServices ))
8580 for _ , srv := range initialServices {
86- opts = append (opts , withService (srv ))
81+ serviceCustomizers = append (serviceCustomizers , withService (srv ))
8782 }
8883
89- for _ , opt := range opts {
90- if err := opt .Customize (& genericContainerReq ); err != nil {
91- return nil , err
92- }
93-
94- // transfer options to the config
84+ serviceCustomizers = append (serviceCustomizers , opts ... )
9585
86+ // transfer options to the config
87+ for _ , opt := range serviceCustomizers {
9688 if bucketCustomizer , ok := opt .(bucketCustomizer ); ok {
9789 // If the option is a bucketCustomizer, we need to add the buckets to the request
9890 config .buckets = append (config .buckets , bucketCustomizer .buckets ... )
@@ -113,13 +105,16 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
113105 }
114106 }
115107
116- container , err := testcontainers .GenericContainer (ctx , genericContainerReq )
108+ moduleOpts = append (moduleOpts , serviceCustomizers ... )
109+
110+ ctr , err := testcontainers .Run (ctx , img , moduleOpts ... )
117111 var couchbaseContainer * CouchbaseContainer
118- if container != nil {
119- couchbaseContainer = & CouchbaseContainer {container , config }
112+ if ctr != nil {
113+ couchbaseContainer = & CouchbaseContainer {Container : ctr , config : config }
120114 }
115+
121116 if err != nil {
122- return couchbaseContainer , err
117+ return couchbaseContainer , fmt . Errorf ( "run couchbase: %w" , err )
123118 }
124119
125120 if err = couchbaseContainer .initCluster (ctx ); err != nil {
0 commit comments