bttest - ActiveState ActiveGo 1.8
...

Package bttest

import "cloud.google.com/go/bigtable/bttest"
Overview
Index
Examples

Overview ▾

Package bttest contains test helpers for working with the bigtable package.

To use a Server, create it, and then connect to it with no security: (The project/instance values are ignored.)

srv, err := bttest.NewServer("127.0.0.1:0")
...
conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure())
...
client, err := bigtable.NewClient(ctx, proj, instance,
        option.WithGRPCConn(conn))
...

type Server

Server is an in-memory Cloud Bigtable fake. It is unauthenticated, and only a rough approximation.

type Server struct {
    Addr string
    // contains filtered or unexported fields
}

func NewServer

func NewServer(laddr string, opt ...grpc.ServerOption) (*Server, error)

NewServer creates a new Server. The Server will be listening for gRPC connections, without TLS, on the provided address. The resolved address is named by the Addr field.

Example

Code:

srv, err := bttest.NewServer("127.0.0.1:0")

if err != nil {
    log.Fatalln(err)
}

ctx := context.Background()

conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure())
if err != nil {
    log.Fatalln(err)
}

proj, instance := "proj", "instance"

adminClient, err := bigtable.NewAdminClient(ctx, proj, instance, option.WithGRPCConn(conn))
if err != nil {
    log.Fatalln(err)
}

if err = adminClient.CreateTable(ctx, "example"); err != nil {
    log.Fatalln(err)
}

if err = adminClient.CreateColumnFamily(ctx, "example", "links"); err != nil {
    log.Fatalln(err)
}

client, err := bigtable.NewClient(ctx, proj, instance, option.WithGRPCConn(conn))
if err != nil {
    log.Fatalln(err)
}
tbl := client.Open("example")

mut := bigtable.NewMutation()
mut.Set("links", "golang.org", bigtable.Now(), []byte("Gophers!"))
if err = tbl.Apply(ctx, "com.google.cloud", mut); err != nil {
    log.Fatalln(err)
}

if row, err := tbl.ReadRow(ctx, "com.google.cloud"); err != nil {
    log.Fatalln(err)
} else {
    for _, column := range row["links"] {
        fmt.Println(column.Column)
        fmt.Println(string(column.Value))
    }
}

Output:

links:golang.org
Gophers!

func (*Server) Close

func (s *Server) Close()

Close shuts down the server.