-
Notifications
You must be signed in to change notification settings - Fork 21
/
app_test.go
91 lines (74 loc) · 2.18 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package firebase_test
import (
"context"
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/api/option"
"github.com/acoshift/go-firebase-admin"
)
type config struct {
ProjectID string `yaml:"projectId"`
DatabaseURL string `yaml:"databaseURL"`
DatabaseAuthVariableOverride interface{} `yaml:"DatabaseAuthVariableOverride"`
APIKey string `yaml:"apiKey"`
}
func initApp(t *testing.T) *firebase.App {
// t.Helper()
// load config from env
c := config{
ProjectID: os.Getenv("PROJECT_ID"),
DatabaseURL: os.Getenv("DATABASE_URL"),
APIKey: os.Getenv("API_KEY"),
}
app, _ := firebase.InitializeApp(context.Background(), firebase.AppOptions{
ProjectID: c.ProjectID,
DatabaseURL: c.DatabaseURL,
DatabaseAuthVariableOverride: c.DatabaseAuthVariableOverride,
APIKey: c.APIKey,
}, option.WithCredentialsFile("private/service_account.json"))
return app
}
func initAppServiceAccount(t *testing.T) *firebase.App {
// t.Helper()
// load config from env
c := config{
ProjectID: os.Getenv("PROJECT_ID"),
DatabaseURL: os.Getenv("DATABASE_URL"),
APIKey: os.Getenv("API_KEY"),
}
serviceAccount, err := ioutil.ReadFile("private/service_account.json")
if err != nil {
assert.Fail(t, "can not load service account; %v", err)
}
app, _ := firebase.InitializeApp(context.Background(), firebase.AppOptions{
ProjectID: c.ProjectID,
ServiceAccount: serviceAccount,
DatabaseURL: c.DatabaseURL,
DatabaseAuthVariableOverride: c.DatabaseAuthVariableOverride,
APIKey: c.APIKey,
})
return app
}
func initApps(t *testing.T) []*firebase.App {
return []*firebase.App{initApp(t), initAppServiceAccount(t)}
}
func TestAuth(t *testing.T) {
app := initApp(t)
firAuth := app.Auth()
assert.NotNil(t, app)
assert.NotNil(t, firAuth)
}
func TestDatabase(t *testing.T) {
app := initApp(t)
firDatabase := app.Database()
assert.NotNil(t, app)
assert.NotNil(t, firDatabase)
}
func TestFCM(t *testing.T) {
app := initApp(t)
firFCM := app.FCM()
assert.NotNil(t, app)
assert.NotNil(t, firFCM)
}