forked from acoshift/go-firebase-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_test.go
65 lines (50 loc) · 1.42 KB
/
app_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package firebase_test
import (
"context"
"io/ioutil"
"os"
"testing"
"github.com/acoshift/go-firebase-admin"
"github.com/stretchr/testify/assert"
)
type config struct {
ProjectID string `yaml:"projectId"`
ServiceAccount []byte `yaml:"serviceAccount"`
DatabaseURL string `yaml:"databaseURL"`
DatabaseAuthVariableOverride interface{} `yaml:"DatabaseAuthVariableOverride"`
APIKey string `yaml:"apiKey"`
}
func initApp() *firebase.App {
// load config from env
c := config{
ProjectID: os.Getenv("PROJECT_ID"),
ServiceAccount: []byte(os.Getenv("SERVICE_ACCOUNT")),
DatabaseURL: os.Getenv("DATABASE_URL"),
APIKey: os.Getenv("API_KEY"),
}
// if service account is in separate file service_account.json
if len(c.ServiceAccount) <= 0 {
serviceAccount, _ := ioutil.ReadFile("private/service_account.json")
c.ServiceAccount = serviceAccount
}
app, _ := firebase.InitializeApp(context.Background(), firebase.AppOptions(c))
return app
}
func TestAuth(t *testing.T) {
app := initApp()
firAuth := app.Auth()
assert.NotNil(t, app)
assert.NotNil(t, firAuth)
}
func TestDatabase(t *testing.T) {
app := initApp()
firDatabase := app.Database()
assert.NotNil(t, app)
assert.NotNil(t, firDatabase)
}
func TestFCM(t *testing.T) {
app := initApp()
firFCM := app.FCM()
assert.NotNil(t, app)
assert.NotNil(t, firFCM)
}