Skip to content

Commit 4105b0a

Browse files
committed
fix: rewrote the module based on comments
1 parent 6a88123 commit 4105b0a

File tree

16 files changed

+458
-233
lines changed

16 files changed

+458
-233
lines changed

docs/modules/firebase.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,26 @@ go get github.com/testcontainers/testcontainers-go/modules/firebase
1717
## Usage example
1818

1919
<!--codeinclude-->
20-
[Creating a Firebase container](../../modules/firebase/examples_test.go) inside_block:runFirebaseContainer
20+
[Creating a Firebase container](../../modules/firebase/examples_test.go) inside_block:ExampleRun
2121
<!--/codeinclude-->
2222

23-
## Module reference
23+
## Module Reference
2424

25-
The Firebase module exposes one entrypoint function to create the Firebase container, and this function receives two parameters:
25+
### Run function
26+
27+
- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>
28+
29+
!!!info
30+
The `RunContainer(ctx, opts...)` function is deprecated and will be removed in the next major release of _Testcontainers for Go_.
31+
32+
The Firebase module exposes one entrypoint function to create the Firebase container, and this function receives three parameters:
2633

2734
```golang
28-
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*FirebaseContainer, error)
35+
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*FirebaseContainer, error)
2936
```
3037

3138
- `context.Context`, the Go context.
39+
- `string`, the Docker image to use.
3240
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.
3341

3442
### Container Options
@@ -37,8 +45,8 @@ When starting the Firebase container, you can pass options in a variadic way to
3745

3846
#### Image
3947

40-
If you need to set a different Firebase Docker image, you can use `testcontainers.WithImage` with a valid Docker image
41-
for Firebase. E.g. `testcontainers.WithImage("ghcr.io/thoughtgears/docker-firebase-emulator:13.6.0")`.
48+
If you need to set a different Firebase Docker image, you can set a valid Docker image as the second argument in the `Run` function.
49+
E.g. `Run(context.Background(), "ghcr.io/u-health/docker-firebase-emulator:13.29.2")`.
4250

4351
{% include "../features/common_functional_options.md" %}
4452

modules/firebase/anchor_test.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

modules/firebase/config.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package firebase
2+
3+
// Based on https://github.com/firebase/firebase-tools/blob/master/src/firebaseConfig.ts
4+
5+
type EmulatorsConfig struct {
6+
SingleProjectMode bool `json:"singleProjectMode,omitempty"`
7+
8+
Auth struct {
9+
Host string `json:"host,omitempty"`
10+
Port int `json:"port,omitempty"`
11+
} `json:"auth,omitempty"`
12+
13+
Database struct {
14+
Host string `json:"host,omitempty"`
15+
Port int `json:"port,omitempty"`
16+
} `json:"database,omitempty"`
17+
18+
Firestore struct {
19+
Host string `json:"host,omitempty"`
20+
Port int `json:"port,omitempty"`
21+
WebsocketPort int `json:"websocketPort,omitempty"`
22+
} `json:"firestore,omitempty"`
23+
24+
Functions struct {
25+
Host string `json:"host,omitempty"`
26+
Port int `json:"port,omitempty"`
27+
} `json:"functions,omitempty"`
28+
29+
Hosting struct {
30+
Host string `json:"host,omitempty"`
31+
Port int `json:"port,omitempty"`
32+
} `json:"hosting,omitempty"`
33+
34+
AppHosting struct {
35+
Host string `json:"host,omitempty"`
36+
Port int `json:"port,omitempty"`
37+
StartCommand string `json:"startCommand,omitempty"`
38+
RootDirectory string `json:"rootDirectory,omitempty"`
39+
} `json:"apphosting,omitempty"`
40+
41+
PubSub struct {
42+
Host string `json:"host,omitempty"`
43+
Port int `json:"port,omitempty"`
44+
} `json:"pubsub,omitempty"`
45+
46+
Storage struct {
47+
Host string `json:"host,omitempty"`
48+
Port int `json:"port,omitempty"`
49+
} `json:"storage,omitempty"`
50+
51+
Logging struct {
52+
Host string `json:"host,omitempty"`
53+
Port int `json:"port,omitempty"`
54+
} `json:"logging,omitempty"`
55+
56+
Hub struct {
57+
Host string `json:"host,omitempty"`
58+
Port int `json:"port,omitempty"`
59+
} `json:"hub,omitempty"`
60+
61+
UI struct {
62+
Enabled bool `json:"enabled,omitempty"`
63+
Host string `json:"host,omitempty"`
64+
Port int `json:"port,omitempty"`
65+
} `json:"ui,omitempty"`
66+
67+
EventArc struct {
68+
Host string `json:"host,omitempty"`
69+
Port int `json:"port,omitempty"`
70+
} `json:"eventarc,omitempty"`
71+
72+
DataConnect struct {
73+
Host string `json:"host,omitempty"`
74+
Port int `json:"port,omitempty"`
75+
PostgresHost string `json:"postgresHost,omitempty"`
76+
PostgresPort int `json:"postgresPort,omitempty"`
77+
DataDir string `json:"dataDir,omitempty"`
78+
} `json:"dataconnect,omitempty"`
79+
80+
Tasks struct {
81+
Host string `json:"host,omitempty"`
82+
Port int `json:"port,omitempty"`
83+
} `json:"tasks,omitempty"`
84+
}
85+
type FirebaseConfig struct {
86+
Emulators EmulatorsConfig `json:"emulators,omitempty"`
87+
}

modules/firebase/examples_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@ import (
66
"log"
77
"path/filepath"
88

9+
"github.com/testcontainers/testcontainers-go"
910
"github.com/testcontainers/testcontainers-go/modules/firebase"
1011
)
1112

12-
func ExampleRunContainer() {
13-
// runFirebaseContainer {
13+
func ExampleRun() {
1414
ctx := context.Background()
1515

16-
firebaseContainer, err := firebase.RunContainer(
17-
ctx,
18-
firebase.WithRoot(filepath.Join(BasePath(), "firebase")),
16+
firebaseContainer, err := firebase.Run(ctx, "ghcr.io/u-health/docker-firebase-emulator:13.29.2",
17+
firebase.WithRoot(filepath.Join(".", "firebase")),
18+
firebase.WithCache(),
1919
)
20-
if err != nil {
21-
log.Fatalf("failed to start container: %s", err)
22-
}
23-
24-
// Clean up the container
2520
defer func() {
26-
if err := firebaseContainer.Terminate(ctx); err != nil {
27-
log.Fatalf("failed to terminate container: %s", err) // nolint:gocritic
21+
if err := testcontainers.TerminateContainer(firebaseContainer); err != nil {
22+
log.Printf("failed to terminate container: %s", err)
2823
}
2924
}()
25+
if err != nil {
26+
log.Printf("failed to start container: %s", err)
27+
return
28+
}
3029
// }
3130

3231
state, err := firebaseContainer.State(ctx)
3332
if err != nil {
34-
log.Fatalf("failed to get container state: %s", err) // nolint:gocritic
33+
log.Printf("failed to get container state: %s", err)
34+
return
3535
}
3636

3737
fmt.Println(state.Running)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "test"
4+
}
5+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"emulators": {
3+
"ui": {
4+
"//": "UI will only partially work in the container. Because ports get mangled, some of the features will be broken. A solution is to run UI externally and provide the mangled ports as inputs.",
5+
"enabled": true,
6+
"port": 4000,
7+
"host": "0.0.0.0"
8+
},
9+
"hub": {
10+
"port": 4400,
11+
"host": "0.0.0.0"
12+
},
13+
"logging": {
14+
"port": 4600,
15+
"host": "0.0.0.0"
16+
},
17+
"firestore": {
18+
"port": 8080,
19+
"host": "0.0.0.0",
20+
"websocketPort": 8081
21+
},
22+
"auth": {
23+
"port": 9099,
24+
"host": "0.0.0.0"
25+
},
26+
"storage": {
27+
"port": 9199,
28+
"host": "0.0.0.0"
29+
},
30+
"singleProjectMode": true
31+
},
32+
"firestore": {
33+
"rules": "firestore.rules",
34+
"indexes": "firestore.indexes.json"
35+
},
36+
"storage": {
37+
"rules": "storage.rules"
38+
}
39+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"indexes": [],
3+
"fieldOverrides": []
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rules_version = '2';
2+
service cloud.firestore {
3+
match /databases/{database}/documents {
4+
match /{document=**} {
5+
allow read, write: if false;
6+
}
7+
}
8+
}
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
rules_version = '2';
2+
service firebase.storage {
3+
match /b/{bucket}/o {
4+
match /{allPaths=**} {
5+
allow read, write: if true;
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)