-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.go
44 lines (40 loc) · 1.48 KB
/
new.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
package mockcbt
import (
"context"
"cloud.google.com/go/bigtable"
errors "github.com/weathersource/go-errors"
"google.golang.org/api/option"
"google.golang.org/grpc"
)
// New creates a new BigTable Client and MockServer
func New() (*bigtable.Client, *MockBtServer, error) {
srv, err := newBtServer()
if err != nil {
return nil, nil, errors.NewUnknownError("Failed to create BigTable server.")
}
conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
return nil, nil, errors.NewUnknownError("Failed to create BigTable connection.")
}
client, err := bigtable.NewClient(context.Background(), "projectID", "instanceID", option.WithGRPCConn(conn))
if err != nil {
return nil, nil, errors.NewUnknownError("Failed to create BigTable client.")
}
return client, srv, nil
}
// NewAdmin creates a new BigTable AdminClient and MockServer
func NewAdmin() (*bigtable.AdminClient, *MockBtAdminServer, error) {
srv, err := newBtAdminServer()
if err != nil {
return nil, nil, errors.NewUnknownError("Failed to create BigTable Admin server.")
}
conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
return nil, nil, errors.NewUnknownError("Failed to create BigTable Admin connection.")
}
client, err := bigtable.NewAdminClient(context.Background(), "projectID", "instanceID", option.WithGRPCConn(conn))
if err != nil {
return nil, nil, errors.NewUnknownError("Failed to create BigTable Admin client.")
}
return client, srv, nil
}