@@ -52,7 +52,10 @@ func acquireLock() (*os.File, error) {
5252 f , err := os .OpenFile (lockFile , os .O_CREATE | os .O_EXCL | os .O_WRONLY , 0644 )
5353 if err == nil {
5454 // Write our PID to the lock file
55- fmt .Fprintf (f , "%d" , os .Getpid ())
55+ _ , errF := fmt .Fprintf (f , "%d" , os .Getpid ())
56+ if errF != nil {
57+ return nil , errF
58+ }
5659 return f , nil
5760 }
5861 // Lock file exists, wait and retry
@@ -64,8 +67,14 @@ func acquireLock() (*os.File, error) {
6467// releaseLock releases the file-based lock
6568func releaseLock (f * os.File ) {
6669 if f != nil {
67- f .Close ()
68- os .Remove (getLockFilePath ())
70+ errC := f .Close ()
71+ if errC != nil {
72+ return
73+ }
74+ errR := os .Remove (getLockFilePath ())
75+ if errR != nil {
76+ return
77+ }
6978 }
7079}
7180
@@ -186,14 +195,17 @@ func TestMain(m *testing.M) {
186195 }
187196
188197 // Clean up state file
189- os .Remove (getStateFilePath ())
198+ errR := os .Remove (getStateFilePath ())
199+ if errR != nil {
200+ return
201+ }
190202 }
191203
192204 os .Exit (code )
193205}
194206
195207func startSharedMongoDBContainer (ctx context.Context ) error {
196- container , err := mongodb .RunContainer (ctx , testcontainers . WithImage ( "mongo:7.0.25-jammy" ) )
208+ container , err := mongodb .Run (ctx , "mongo:7.0.25-jammy" )
197209 if err != nil {
198210 return fmt .Errorf ("failed to start MongoDB container: %w" , err )
199211 }
@@ -335,41 +347,3 @@ type MyLogConsumer struct{}
335347func (c * MyLogConsumer ) Accept (log testcontainers.Log ) {
336348 fmt .Printf ("Log: %s\n " , string (log .Content ))
337349}
338-
339- // startCouchDBContainer starts a CouchDB container and returns the container and connection URL
340- func startCouchDBContainer (ctx context.Context ) (testcontainers.Container , string , error ) {
341- consumer := & MyLogConsumer {}
342- req := testcontainers.ContainerRequest {
343- Image : "couchdb:3.4.3" ,
344- ExposedPorts : []string {"5984/tcp" },
345- WaitingFor : wait .ForListeningPort ("5984/tcp" ),
346- Env : map [string ]string {
347- "COUCHDB_USER" : "admin" ,
348- "COUCHDB_PASSWORD" : "password" ,
349- },
350- LogConsumerCfg : & testcontainers.LogConsumerConfig {
351- Consumers : []testcontainers.LogConsumer {
352- consumer ,
353- },
354- },
355- }
356- container , err := testcontainers .GenericContainer (ctx , testcontainers.GenericContainerRequest {
357- ContainerRequest : req ,
358- Started : true ,
359- })
360- if err != nil {
361- return nil , "" , err
362- }
363- host , err := container .Host (ctx )
364- if err != nil {
365- container .Terminate (ctx )
366- return nil , "" , err
367- }
368- port , err := container .MappedPort (ctx , "5984" )
369- if err != nil {
370- container .Terminate (ctx )
371- return nil , "" , err
372- }
373- url := fmt .Sprintf ("http://admin:password@%s:%s" , host , port .Port ())
374- return container , url , nil
375- }
0 commit comments