Documentation
¶
Overview ¶
Package testhelpers provides shared testing utilities used across unit and acceptance tests.
Intended use:
- Unit tests: builders, fixtures, and assertions to reduce boilerplate.
- Acceptance tests: environment pre-checks, deterministic name generators, retry/backoff test stubs, and helpers for external service setup/teardown.
- HTTP/logging tests: redaction utilities, fake clients/round-trippers, and golden-file helpers with stable, sorted outputs.
Conventions:
- Keep dependencies minimal and avoid importing production-only paths.
- Ensure deterministic outputs: sort collections, use stable IDs, and normalize values before comparisons or serialization.
- Never leak secrets in logs, errors, or golden files; always redact.
This package is for test code and is not part of the provider's public API.
Index ¶
- Constants
- Variables
- func BuildLargeBody() string
- func GetFieldResCfg(t *testing.T, data FieldTemplateData) string
- func GetProjCatCfg(t *testing.T, name, desc string) string
- func GetProjCfgStr(t *testing.T, key, name, projectType, leadAccountID, description string) string
- func GetProjCfgWithDsTmpl(t *testing.T, key, name, projectType, lookupType string) string
- func GetTestProjLeadAcctIdFromEnv() string
- func MkRS(code int, headers http.Header, body string) *models.ResponseScheme
- func MkRSWithBodyAndHeaders(code int, hdr http.Header, body string) *models.ResponseScheme
- func MustCopy(t *testing.T, name string, r io.Reader) string
- func MustReadTemplate(t *testing.T, name string) string
- func RandString(n int) string
- func TemplatePath(name string) string
- type DataProjectsCfg
- type FakeNetErr
- type FakeTypeService
- func (f *FakeTypeService) Create(ctx context.Context, payload *models.IssueTypePayloadScheme) (*models.IssueTypeScheme, *models.ResponseScheme, error)
- func (f *FakeTypeService) Delete(ctx context.Context, id string) (*models.ResponseScheme, error)
- func (f *FakeTypeService) Get(ctx context.Context, id string) (*models.IssueTypeScheme, *models.ResponseScheme, error)
- func (f *FakeTypeService) Update(ctx context.Context, id string, payload *models.IssueTypePayloadScheme) (*models.IssueTypeScheme, *models.ResponseScheme, error)
- type FieldTemplateData
- type ProjectCatTmplCfg
- type ProjectTmplCfg
Constants ¶
const ( // DataWorkTypesTmpl is the filename for the data.work_types Terraform template. DataWorkTypesTmpl = "data.work_types.tf.tmpl" // WorkTypeTmpl is the filename for the work_type Terraform template. WorkTypeTmpl = "work_type.tf.tmpl" // DataProjectTmpl is the filename for the data.projects Terraform template. DataProjectTmpl = "data.projects.tf.tmpl" // ProjectTmpl is the filename for the project Terraform template. ProjectTmpl = "project.tf.tmpl" // ProjectCatTmpl is the filename for the project_category Terraform template. ProjectCatTmpl = "project_category.tf.tmpl" // FieldTmpl is the filename for the field Terraform template. FieldTmpl = "field.tf.tmpl" )
const ( StandardWorkType = 0 SubtaskWorkType = -1 )
Work type identifiers.
const ( HierarchyStandard = 0 HierarchySubtask = -1 )
Common hierarchy levels used across tests.
const TemplatesDir = "templates"
TemplatesDir defines the base directory for template files.
Variables ¶
var ( DataWorkTypesTmplPath = tmplPath(DataWorkTypesTmpl) WorkTypeTmplPath = tmplPath(WorkTypeTmpl) DataProjectTmplPath = tmplPath(DataProjectTmpl) ProjectTmplPath = tmplPath(ProjectTmpl) ProjectCatTmplPath = tmplPath(ProjectCatTmpl) FieldTmplPath = tmplPath(FieldTmpl) )
Functions ¶
func BuildLargeBody ¶
func BuildLargeBody() string
BuildLargeBody creates a large JSON-like string embedding various secrets to validate both truncation and redaction. Size target ~2MB.
func GetFieldResCfg ¶ added in v0.8.0
func GetFieldResCfg(t *testing.T, data FieldTemplateData) string
GetFieldResCfg generates a Terraform field resource configuration using the provided template data.
func GetProjCfgStr ¶ added in v0.8.0
func GetProjCfgWithDsTmpl ¶ added in v0.8.0
GetProjCfgWithDsTmpl generates a Terraform configuration string for creating a Jira project and data sources. This function requires project attributes such as key, name, project type, and lookup type. It uses a template file to build the configuration and executes it with provided parameters. The returned string can be used in acceptance tests to verify resource and data source integration.
func GetTestProjLeadAcctIdFromEnv ¶ added in v0.8.0
func GetTestProjLeadAcctIdFromEnv() string
func MkRSWithBodyAndHeaders ¶
func MustReadTemplate ¶
MustReadTemplate reads a template by name or fails the test.
func RandString ¶ added in v0.8.0
RandString provides a simple deterministic-ish suffix for names when acctest isn't required. We prefer acctest.RandomWithPrefix elsewhere; here we keep it self-contained.
func TemplatePath ¶
TemplatePath returns an absolute path to a template file under testdata/templates.
Types ¶
type DataProjectsCfg ¶ added in v0.6.0
type FakeNetErr ¶
type FakeNetErr struct {
// contains filtered or unexported fields
}
FakeNetErr for testing ShouldRetry timeout path
func NewFakeNetErr ¶
func NewFakeNetErr(timeout bool) FakeNetErr
NewFakeNetErr constructs a FakeNetErr with the provided timeout flag.
func (FakeNetErr) Error ¶
func (e FakeNetErr) Error() string
func (FakeNetErr) Temporary ¶
func (e FakeNetErr) Temporary() bool
func (FakeNetErr) Timeout ¶
func (e FakeNetErr) Timeout() bool
type FakeTypeService ¶
type FakeTypeService struct {
CreateFn func(ctx context.Context, payload *models.IssueTypePayloadScheme) (*models.IssueTypeScheme, *models.ResponseScheme, error)
GetFn func(ctx context.Context, id string) (*models.IssueTypeScheme, *models.ResponseScheme, error)
UpdateFn func(ctx context.Context, id string, payload *models.IssueTypePayloadScheme) (*models.IssueTypeScheme, *models.ResponseScheme, error)
DeleteFn func(ctx context.Context, id string) (*models.ResponseScheme, error)
}
FakeTypeService provides a minimal test double for jira.TypeConnector used in unit tests. It exposes function fields so tests can customize behavior per case.
func (*FakeTypeService) Create ¶
func (f *FakeTypeService) Create(ctx context.Context, payload *models.IssueTypePayloadScheme) (*models.IssueTypeScheme, *models.ResponseScheme, error)
func (*FakeTypeService) Delete ¶
func (f *FakeTypeService) Delete(ctx context.Context, id string) (*models.ResponseScheme, error)
func (*FakeTypeService) Get ¶
func (f *FakeTypeService) Get(ctx context.Context, id string) (*models.IssueTypeScheme, *models.ResponseScheme, error)
func (*FakeTypeService) Update ¶
func (f *FakeTypeService) Update(ctx context.Context, id string, payload *models.IssueTypePayloadScheme) (*models.IssueTypeScheme, *models.ResponseScheme, error)
type FieldTemplateData ¶ added in v0.8.0
fieldTemplateData represents the structure for storing field information such as name, type, and description.