@@ -28,9 +28,7 @@ func (c *SurrealDBContainer) URL(ctx context.Context) (string, error) {
2828// It will create the specified user with superuser power.
2929func WithUsername (username string ) testcontainers.CustomizeRequestOption {
3030 return func (req * testcontainers.GenericContainerRequest ) error {
31- req .Env ["SURREAL_USER" ] = username
32-
33- return nil
31+ return testcontainers .WithEnv (map [string ]string {"SURREAL_USER" : username })(req )
3432 }
3533}
3634
@@ -39,36 +37,28 @@ func WithUsername(username string) testcontainers.CustomizeRequestOption {
3937// It will set the superuser password for SurrealDB.
4038func WithPassword (password string ) testcontainers.CustomizeRequestOption {
4139 return func (req * testcontainers.GenericContainerRequest ) error {
42- req .Env ["SURREAL_PASS" ] = password
43-
44- return nil
40+ return testcontainers .WithEnv (map [string ]string {"SURREAL_PASS" : password })(req )
4541 }
4642}
4743
4844// WithAuthentication enables authentication for the SurrealDB instance
4945func WithAuthentication () testcontainers.CustomizeRequestOption {
5046 return func (req * testcontainers.GenericContainerRequest ) error {
51- req .Env ["SURREAL_AUTH" ] = "true"
52-
53- return nil
47+ return testcontainers .WithEnv (map [string ]string {"SURREAL_AUTH" : "true" })(req )
5448 }
5549}
5650
5751// WithStrictMode enables strict mode for the SurrealDB instance
5852func WithStrictMode () testcontainers.CustomizeRequestOption {
5953 return func (req * testcontainers.GenericContainerRequest ) error {
60- req .Env ["SURREAL_STRICT" ] = "true"
61-
62- return nil
54+ return testcontainers .WithEnv (map [string ]string {"SURREAL_STRICT" : "true" })(req )
6355 }
6456}
6557
6658// WithAllowAllCaps enables all caps for the SurrealDB instance
6759func WithAllowAllCaps () testcontainers.CustomizeRequestOption {
6860 return func (req * testcontainers.GenericContainerRequest ) error {
69- req .Env ["SURREAL_CAPS_ALLOW_ALL" ] = "false"
70-
71- return nil
61+ return testcontainers .WithEnv (map [string ]string {"SURREAL_CAPS_ALLOW_ALL" : "false" })(req )
7262 }
7363}
7464
@@ -80,42 +70,28 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
8070
8171// Run creates an instance of the SurrealDB container type
8272func Run (ctx context.Context , img string , opts ... testcontainers.ContainerCustomizer ) (* SurrealDBContainer , error ) {
83- req := testcontainers.ContainerRequest {
84- Image : img ,
85- Env : map [string ]string {
73+ moduleOpts := []testcontainers.ContainerCustomizer {
74+ testcontainers .WithEnv (map [string ]string {
8675 "SURREAL_USER" : "root" ,
8776 "SURREAL_PASS" : "root" ,
8877 "SURREAL_AUTH" : "false" ,
8978 "SURREAL_STRICT" : "false" ,
9079 "SURREAL_CAPS_ALLOW_ALL" : "false" ,
9180 "SURREAL_PATH" : "memory" ,
92- },
93- ExposedPorts : []string {"8000/tcp" },
94- WaitingFor : wait .ForAll (
95- wait .ForLog ("Started web server on " ),
96- ),
97- Cmd : []string {"start" },
98- }
99-
100- genericContainerReq := testcontainers.GenericContainerRequest {
101- ContainerRequest : req ,
102- Started : true ,
103- }
104-
105- for _ , opt := range opts {
106- if err := opt .Customize (& genericContainerReq ); err != nil {
107- return nil , fmt .Errorf ("customize: %w" , err )
108- }
81+ }),
82+ testcontainers .WithExposedPorts ("8000/tcp" ),
83+ testcontainers .WithWaitStrategy (wait .ForLog ("Started web server on " )),
84+ testcontainers .WithCmd ("start" ),
10985 }
11086
111- container , err := testcontainers .GenericContainer (ctx , genericContainerReq )
87+ ctr , err := testcontainers .Run (ctx , img , append ( moduleOpts , opts ... ) ... )
11288 var c * SurrealDBContainer
113- if container != nil {
114- c = & SurrealDBContainer {Container : container }
89+ if ctr != nil {
90+ c = & SurrealDBContainer {Container : ctr }
11591 }
11692
11793 if err != nil {
118- return c , fmt .Errorf ("generic container : %w" , err )
94+ return c , fmt .Errorf ("run surrealdb : %w" , err )
11995 }
12096
12197 return c , nil
0 commit comments