go: cloud.google.com/go/bigtable/bttest Index | Examples | Files

package bttest

import "cloud.google.com/go/bigtable/bttest"

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))
...

Index

Examples

Package Files

inmem.go

type Server Uses

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

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

func NewServer Uses

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.

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 Uses

func (s *Server) Close()

Close shuts down the server.

Package bttest imports 19 packages (graph) and is imported by 2 packages. Updated 2017-07-21. Refresh now. Tools for package owners.