mockbigquery

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 10 Imported by: 0

README

Mock BigQuery Emulator

Tests goreportcard

Provide a mock BigQuery Emulator instance and optionally a mock BigQuery client for testing purposes. This library is built so you can mock BigQuery using the bigquery-emulator project. You will need to have Docker running on your local machine or within your CI environment.

This library is built on top of testcontainers.

Usage

Creating a mock instance for creating a customer connection.

func TestXXX(t *testing.T) {
	ctx := context.Background()

    const projectID = "test-project"
	const datasetID = "test-dataset"

	mock, err := mockbigquery.NewInstance(ctx, t, projectID, datasetID)

	if err != nil {
		t.Fatalf("creating the instance: %v", err)
		return
	}

	// close the mock
	defer mock.Close(ctx)

	// ... my test code
}

Creating a mock redis client for interacting with Redis.

func TestXXX(t *testing.T) {
	ctx := context.Background()

	const projectID = "test-project"
	const datasetID = "test-dataset"

	mock, err := mockbigquery.NewClient(ctx, t, projectID, datasetID)

	if err != nil {
		t.Fatalf("creating the client: %v", err)
		return
	}

	// close the mock
	defer mock.Close(ctx)

    bqClient := mock.Client()

	// ... my test code
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the Redis client and the underlying instance for testing. It provides helper methods for accessing the client, closing the client, and closing the instance.

func NewClient

func NewClient(ctx context.Context, t *testing.T, projectID string, datasetID string) (*Client, error)

NewClient creates a new BigQuery client that connects to an underlying emulator instance for testing.

func (*Client) Client

func (r *Client) Client() *bigquery.Client

Client returns the underlying Redis client.

func (*Client) Close

func (r *Client) Close(ctx context.Context)

Close closes the underlying BigQuery client and the instance.

func (*Client) DatasetID

func (c *Client) DatasetID() string

DatasetID returns the dataset id of the underlying instance.

func (*Client) FullName

func (c *Client) FullName() string

FullName returns the fullly qualified dataset name.

func (*Client) ProjectID

func (c *Client) ProjectID() string

ProjectID returns the project id of the underlying instance.

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

Instance represents the underlying container that is running the mock redis instance.

func NewInstance

func NewInstance(ctx context.Context, t *testing.T, project string, dataset string) (*Instance, error)

NewInstance creates a new BigQuery Emulator container. It will exponentially backoff until the container is ready to accept connections so that you can handle throttling within CI environments

func (*Instance) Close

func (r *Instance) Close(ctx context.Context)

Close terminates the underlying container.

func (*Instance) DatasetID

func (r *Instance) DatasetID() string

DatasetID returns the dataset id of the underlying instance.

func (*Instance) Port

func (r *Instance) Port(ctx context.Context) (nat.Port, error)

Port returns the mapped port of the underlying container.

func (*Instance) ProjectID

func (r *Instance) ProjectID() string

ProjectID returns the project id of the underlying instance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL