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")
|
||
|
|
}
|
||
|
|
}
|