-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudsync_service_iface_test.go
More file actions
45 lines (39 loc) · 1.04 KB
/
cloudsync_service_iface_test.go
File metadata and controls
45 lines (39 loc) · 1.04 KB
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
package truenas
import (
"context"
"testing"
)
func TestMockCloudSyncService_ImplementsInterface(t *testing.T) {
var _ CloudSyncServiceAPI = (*CloudSyncService)(nil)
var _ CloudSyncServiceAPI = (*MockCloudSyncService)(nil)
}
func TestMockCloudSyncService_DefaultsToNil(t *testing.T) {
mock := &MockCloudSyncService{}
ctx := context.Background()
cred, err := mock.GetCredential(ctx, 1)
if err != nil {
t.Fatalf("expected nil error, got: %v", err)
}
if cred != nil {
t.Fatalf("expected nil result, got: %v", cred)
}
}
func TestMockCloudSyncService_CallsFunc(t *testing.T) {
called := false
mock := &MockCloudSyncService{
GetCredentialFunc: func(ctx context.Context, id int64) (*CloudSyncCredential, error) {
called = true
return &CloudSyncCredential{ID: id}, nil
},
}
cred, err := mock.GetCredential(context.Background(), 42)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !called {
t.Fatal("expected GetCredentialFunc to be called")
}
if cred.ID != 42 {
t.Fatalf("expected ID 42, got %d", cred.ID)
}
}