Skip to content

Commit cc2bfa4

Browse files
committed
fix: another pass at comments
1 parent 4105b0a commit cc2bfa4

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

modules/firebase/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package firebase
22

33
// Based on https://github.com/firebase/firebase-tools/blob/master/src/firebaseConfig.ts
44

5-
type EmulatorsConfig struct {
5+
type emulatorsConfig struct {
66
SingleProjectMode bool `json:"singleProjectMode,omitempty"`
77

88
Auth struct {
@@ -82,6 +82,6 @@ type EmulatorsConfig struct {
8282
Port int `json:"port,omitempty"`
8383
} `json:"tasks,omitempty"`
8484
}
85-
type FirebaseConfig struct {
86-
Emulators EmulatorsConfig `json:"emulators,omitempty"`
85+
type partialFirebaseConfig struct {
86+
Emulators emulatorsConfig `json:"emulators,omitempty"`
8787
}

modules/firebase/examples_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func ExampleRun() {
2626
log.Printf("failed to start container: %s", err)
2727
return
2828
}
29-
// }
3029

3130
state, err := firebaseContainer.State(ctx)
3231
if err != nil {

modules/firebase/firebase.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func WithCache() testcontainers.CustomizeRequestOption {
6767
}
6868
}
6969

70-
func gatherPorts(config FirebaseConfig) ([]string, error) {
70+
func gatherPorts(config partialFirebaseConfig) ([]string, error) {
7171
var ports []string
7272

7373
v := reflect.ValueOf(config.Emulators)
@@ -128,7 +128,7 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
128128
return file.ContainerFilePath == rootFilePath
129129
})
130130
if rootPathIdx == -1 {
131-
return nil, fmt.Errorf("firebase emulator is unable to boot without configuration root (obtained via 'firebase init')")
131+
return nil, fmt.Errorf("firebase root not provided (WithRoot is required)")
132132
}
133133
// Parse expected emulators from the root:
134134
userRoot := req.ContainerRequest.Files[rootPathIdx].HostFilePath
@@ -141,13 +141,13 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
141141
if err != nil {
142142
return nil, fmt.Errorf("read firebase.json: %w", err)
143143
}
144-
var parsed FirebaseConfig
144+
var parsed partialFirebaseConfig
145145
if err := json.Unmarshal(bytes, &parsed); err != nil {
146146
return nil, fmt.Errorf("parse firebase.json: %w", err)
147147
}
148148
expectedExposedPorts, err := gatherPorts(parsed)
149149
if err != nil {
150-
return nil, fmt.Errorf("issues with emulator config block: %w", err)
150+
return nil, fmt.Errorf("invalid config: %w", err)
151151
}
152152
req.ExposedPorts = expectedExposedPorts
153153

modules/firebase/firebase_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package firebase_test
22

33
import (
44
"context"
5-
"os"
65
"path/filepath"
76
"testing"
87
"time"
98

109
"cloud.google.com/go/firestore"
11-
"github.com/stretchr/testify/assert"
1210
"github.com/stretchr/testify/require"
1311

1412
"github.com/testcontainers/testcontainers-go"
@@ -25,27 +23,30 @@ func TestFirebase(t *testing.T) {
2523
testcontainers.CleanupContainer(t, ctr)
2624
require.NoError(t, err)
2725

28-
// perform assertions
26+
// perform requireions
2927
// Ports are linked to the example config in firebase/firebase.json
3028

3129
firestoreUrl, err := ctr.ConnectionString(ctx, "8080/tcp")
32-
assert.NoError(t, err)
33-
assert.NotEmpty(t, firestoreUrl)
34-
_ = os.Setenv("FIRESTORE_EMULATOR_HOST", firestoreUrl)
30+
require.NoError(t, err)
31+
require.NotEmpty(t, firestoreUrl)
32+
33+
t.Setenv("FIRESTORE_EMULATOR_HOST", firestoreUrl)
3534
c, err := firestore.NewClient(ctx, firestore.DetectProjectID)
3635
require.NoError(t, err)
3736
defer c.Close()
38-
w, err := c.Collection("example").Doc("one").Set(ctx, map[string]interface{}{
37+
38+
w, err := c.Collection("example").Doc("one").Set(ctx, map[string]any{
3939
"foo": "bar",
4040
})
41-
require.NotNil(t, w)
4241
require.NoError(t, err)
42+
require.NotNil(t, w)
43+
4344
snap, err := c.Collection("example").Doc("one").Get(ctx)
4445
require.NoError(t, err)
4546
var out map[string]string
4647
err = snap.DataTo(&out)
4748
require.NoError(t, err)
48-
assert.Equal(t, "bar", out["foo"])
49+
require.Equal(t, "bar", out["foo"])
4950
}
5051

5152
func TestFirebaseBadDirectory(t *testing.T) {
@@ -57,7 +58,7 @@ func TestFirebaseBadDirectory(t *testing.T) {
5758
)
5859
// In this case, the file gets copied over at /srv/failure (instead of /srv/firebase)
5960
// and this stops working.
60-
// What would be a solution here? Previously I just added an assertion that the root must
61+
// What would be a solution here? Previously I just added an requireion that the root must
6162
// end in "/firebase"... I could do the same.
6263
testcontainers.CleanupContainer(t, ctr)
6364
require.NoError(t, err)
@@ -69,6 +70,5 @@ func TestFirebaseRequiresRoot(t *testing.T) {
6970

7071
ctr, err := firebase.Run(ctx, "ghcr.io/u-health/docker-firebase-emulator:13.29.2")
7172
testcontainers.CleanupContainer(t, ctr)
72-
require.Error(t, err)
7373
require.ErrorContains(t, err, "unable to boot without configuration root")
7474
}

0 commit comments

Comments
 (0)