Firebase App component with launcher lifecycle and health check integration.
What's included:
- Config with ProjectID (FIREBASE_PROJECT_ID env var); credentials via ADC
- Provider interface exposing native *firebase.App directly
- Component interface: launcher.Component + health.Checkable + Provider
- New(logger, cfg) constructor for lifecycle registration via lc.Append
- Health check via GetUser("health-probe-non-existent") + auth.IsUserNotFound at LevelCritical
- No-op OnStop (Firebase Admin SDK has no Close method)
Tested-via: todo-api POC integration
Reviewed-against: docs/adr/
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package firebase
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.nochebuena.dev/go/health"
|
|
"code.nochebuena.dev/go/logz"
|
|
)
|
|
|
|
func newLogger() logz.Logger { return logz.New(logz.Options{}) }
|
|
|
|
func TestNew(t *testing.T) {
|
|
if New(newLogger(), Config{ProjectID: "test"}) == nil {
|
|
t.Fatal("New returned nil")
|
|
}
|
|
}
|
|
|
|
func TestComponent_Name(t *testing.T) {
|
|
c := New(newLogger(), Config{ProjectID: "test"}).(health.Checkable)
|
|
if c.Name() != "firebase" {
|
|
t.Errorf("want firebase, got %s", c.Name())
|
|
}
|
|
}
|
|
|
|
func TestComponent_Priority(t *testing.T) {
|
|
c := New(newLogger(), Config{ProjectID: "test"}).(health.Checkable)
|
|
if c.Priority() != health.LevelCritical {
|
|
t.Error("Priority() != LevelCritical")
|
|
}
|
|
}
|
|
|
|
func TestComponent_OnInit_MissingProjectID(t *testing.T) {
|
|
c := New(newLogger(), Config{ProjectID: ""})
|
|
if err := c.OnInit(); err == nil {
|
|
t.Error("expected error for empty ProjectID")
|
|
}
|
|
}
|
|
|
|
func TestComponent_OnStop_NilApp(t *testing.T) {
|
|
c := &firebaseComponent{logger: newLogger()}
|
|
if err := c.OnStop(); err != nil {
|
|
t.Errorf("OnStop with nil app: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestComponent_App_ReturnsNilBeforeInit(t *testing.T) {
|
|
c := New(newLogger(), Config{ProjectID: "test"})
|
|
if c.App() != nil {
|
|
t.Error("App() should be nil before OnInit")
|
|
}
|
|
}
|