Skip to content

Commit e40d2f2

Browse files
committed
Fix firestore coverage
1 parent e83246b commit e40d2f2

File tree

4 files changed

+74
-17
lines changed

4 files changed

+74
-17
lines changed

message/firestore/firestore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func New(ctx context.Context, projectID string, rootDocPath string) (*Provider,
152152
// Note: Use this one for the tests with a mock ClientInterface.
153153
func NewWithClient(ctx context.Context, projectID string, rootDocPath string, client fsClient.ClientInterface) (*Provider, error) {
154154
if client == nil || !client.Authenticated() {
155-
return nil, errors.New("could not authenticate sync client")
155+
return nil, errors.New("firestore: could not authenticate message client")
156156
}
157157

158158
return &Provider{

message/firestore/firestore_test.go

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,36 +143,93 @@ func TestNew(t *testing.T) {
143143
rootDocPath string
144144
}
145145
tests := []struct {
146-
name string
147-
args args
148-
want *Provider
149-
wantErr bool
146+
name string
147+
args args
148+
want reflect.Type
150149
}{
151150
{
152-
"Test New Client - Fail because API access",
151+
"Test New Client",
153152
args{
154153
context.Background(),
155154
"sample-project",
156155
"root-doc",
157156
},
158-
nil,
159-
true,
157+
reflect.TypeOf(&Provider{}),
160158
},
161159
}
162160
for _, tt := range tests {
163161
t.Run(tt.name, func(t *testing.T) {
164-
got, err := New(tt.args.ctx, tt.args.projectID, tt.args.rootDocPath)
165-
if (err != nil) && tt.wantErr {
166-
t.Errorf("New() error = %v, wantErr %v", err, tt.wantErr)
167-
return
162+
if got, _ := New(tt.args.ctx, tt.args.projectID, tt.args.rootDocPath); reflect.TypeOf(got) != tt.want {
163+
t.Errorf("New() = %v, want %v", reflect.TypeOf(got), tt.want)
168164
}
169-
if got != tt.want && !tt.wantErr {
170-
t.Errorf("New() = %v, want %v", got, tt.want)
165+
})
166+
}
167+
}
168+
169+
func TestNewWithClient(t *testing.T) {
170+
type args struct {
171+
ctx context.Context
172+
projectID string
173+
rootDocPath string
174+
client fsClient.ClientInterface
175+
}
176+
tests := []struct {
177+
name string
178+
args args
179+
want reflect.Type
180+
}{
181+
{
182+
"New With Client",
183+
args{
184+
context.Background(),
185+
"random-id",
186+
"collection/doc",
187+
nil,
188+
},
189+
reflect.TypeOf(&Provider{}),
190+
},
191+
}
192+
for _, tt := range tests {
193+
t.Run(tt.name, func(t *testing.T) {
194+
if got, _ := NewWithClient(tt.args.ctx, tt.args.projectID, tt.args.rootDocPath, tt.args.client); reflect.TypeOf(got) != tt.want {
195+
t.Errorf("NewWithClient() = %v, want %v", reflect.TypeOf(got), tt.want)
171196
}
172197
})
173198
}
174199
}
175200

201+
//func TestNew(t *testing.T) {
202+
// type args struct {
203+
// ctx context.Context
204+
// projectID string
205+
// rootDocPath string
206+
// }
207+
// tests := []struct {
208+
// name string
209+
// args args
210+
// want reflect.Type
211+
// wantErr bool
212+
// }{
213+
// {
214+
// "Test New Client - Fail because API access",
215+
// args{
216+
// context.Background(),
217+
// "sample-project",
218+
// "root-doc",
219+
// },
220+
// reflect.TypeOf(&Provider{}),
221+
// true,
222+
// },
223+
// }
224+
// for _, tt := range tests {
225+
// t.Run(tt.name, func(t *testing.T) {
226+
// if got, _ := New(tt.args.ctx, tt.args.projectID, tt.args.rootDocPath); reflect.TypeOf(got) != tt.want {
227+
// t.Errorf("New() = %v, want %v", reflect.TypeOf(got), tt.want)
228+
// }
229+
// })
230+
// }
231+
//}
232+
176233
func TestFirestoreProvider_Close(t *testing.T) {
177234
type fields struct {
178235
ctx context.Context

sync/firestore/firestore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func New(ctx context.Context, projectID string, rootDocPath string) (*Sync, erro
115115
// NewWithClient creates a new Sync (UpdateChecker) with a provided ClientInterface client.
116116
// Note: Use this one for the tests with a mock ClientInterface.
117117
func NewWithClient(ctx context.Context, projectID string, rootDocPath string, client fsClient.ClientInterface) (*Sync, error) {
118-
if !client.Authenticated() {
118+
if client == nil || !client.Authenticated() {
119119
return nil, errors.New("firestore: could not authenticate sync client")
120120
}
121121

sync/firestore/firestore_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func TestNew(t *testing.T) {
395395
want reflect.Type
396396
}{
397397
{
398-
"Test New",
398+
"Test New Client",
399399
args{
400400
context.Background(),
401401
"random-project",
@@ -431,7 +431,7 @@ func TestNewWithClient(t *testing.T) {
431431
context.Background(),
432432
"random-id",
433433
"collection/doc",
434-
&mockClient{},
434+
nil,
435435
},
436436
reflect.TypeOf(&Sync{}),
437437
},

0 commit comments

Comments
 (0)