testhelpers

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

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

func (*MockServer) GetCapturedCalls

func (m *MockServer) GetCapturedCalls(path string) []*CapturedCall

GetCapturedCalls returns all captured calls for a given path

type ResourceTestConfig

type ResourceTestConfig struct {
	ResourceType string
	AccountID    int
	ProjectID    int
	ResourceID   int
	APIPath      string
}

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