testutil

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateResourceTestHandlers

func CreateResourceTestHandlers(t *testing.T, config ResourceTestConfig, tracker *APICallTracker) map[string]MockEndpointHandler

CreateResourceTestHandlers creates standard CRUD handlers for testing any dbt Cloud resource

Types

type APICallTracker

type APICallTracker struct {
	CreateCount int
	ReadCount   int
	UpdateCount int
	DeleteCount int
}

APICallTracker tracks API calls made during testing

type CapturedCall

type CapturedCall struct {
	Method  string
	Path    string
	Headers http.Header
	Body    []byte
}

CapturedCall holds the details of a single HTTP request received by the mock server.

func (*CapturedCall) BodyAsMap

func (c *CapturedCall) BodyAsMap(t *testing.T) map[string]interface{}

BodyAsMap unmarshals the JSON body of the call into a map for easy validation.

type MockEndpointHandler

type MockEndpointHandler func(r *http.Request) (statusCode int, responseBody interface{}, err error)

MockEndpointHandler is a function that inspects a request and dynamically determines the response. If err is non-nil, the server returns a 400 Bad Request with the error message. Otherwise, it returns the specified statusCode and marshals responseBody to JSON.

type MockServer

type MockServer struct {
	*httptest.Server
	// contains filtered or unexported fields
}

MockServer is a wrapper around httptest.Server that captures calls.

func SetupMockServer

func SetupMockServer(t *testing.T, handlers map[string]MockEndpointHandler) *MockServer

SetupMockServer creates and starts a new MockServer using dynamic handlers. The handlers map keys should be in the format "METHOD /path", e.g., "POST /users".

func (*MockServer) GetLastCall

func (s *MockServer) GetLastCall(path string) *CapturedCall

GetLastCall returns the most recent call made to a specific path.

type ResourceTestConfig

type ResourceTestConfig struct {
	ResourceType string // e.g., "dbtcloud_postgres_credential"
	AccountID    int
	ProjectID    int    // Optional, only needed for project-scoped resources
	ResourceID   int    // The main resource ID
	APIPath      string // e.g., "credentials" for /v3/accounts/{account}/projects/{project}/credentials/
}

ResourceTestConfig holds configuration for testing a dbt Cloud resource

Jump to

Keyboard shortcuts

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