Categorygithub.com/arhea/go-mock-bigquery
modulepackage
1.0.4
Repository: https://github.com/arhea/go-mock-bigquery.git
Documentation: pkg.go.dev

# 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
}

# Functions

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

# Structs

Client wraps the Redis client and the underlying instance for testing.
Instance represents the underlying container that is running the mock redis instance.