clustertestutils

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

README

pkg/provisioner/cluster/testutils

This package provides testing utilities for cluster provisioner testing.

Purpose

Contains common test utilities, shared test cases, and helper functions for standardizing test patterns across cluster provisioner packages. This package provides testing infrastructure for Kind, K3d, and EKS cluster provisioning functionality.

Features

  • Common Test Cases: Standardized test patterns for cluster provisioner testing
  • Shared Error Variables: Common error types used across cluster provisioner tests
  • Helper Functions: Utilities for setting up and tearing down test environments
  • Test Standardization: Consistent testing patterns across different provisioner types
  • Error Scenario Testing: Utilities for testing cluster creation and deletion failures

Usage

import clustertestutils "github.com/devantler-tech/ksail-go/pkg/provisioner/cluster/testutils"

func TestClusterProvisioner(t *testing.T) {
    // Use common error variables
    err := provisioner.CreateCluster()
    assert.Equal(t, clustertestutils.ErrCreateClusterFailed, err)

    // Use shared test patterns
    clustertestutils.RunCommonProvisionerTests(t, provisioner)
}

Key Components

  • common.go: Common test utilities and shared functionality
  • error variables: Standardized error types for cluster operations
  • test patterns: Reusable test cases for different provisioner types

Integration

This package is used by cluster provisioner packages for testing:

  • pkg/provisioner/cluster/kind: Kind cluster provisioning tests
  • pkg/provisioner/cluster/k3d: K3d cluster provisioning tests
  • pkg/provisioner/cluster/eks: EKS cluster provisioning tests

This ensures consistent testing patterns and reduces code duplication across all cluster provisioner functionality.


⬅️ Go Back

Documentation

Overview

Package clustertestutils provides common test utilities for cluster provisioner testing, including shared test cases and helper functions for standardizing test patterns.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCreateClusterFailed  = errors.New("create cluster failed")
	ErrDeleteClusterFailed  = errors.New("delete cluster failed")
	ErrListClustersFailed   = errors.New("list clusters failed")
	ErrStartClusterFailed   = errors.New("start cluster failed")
	ErrStopClusterFailed    = errors.New("stop cluster failed")
	ErrScaleNodeGroupFailed = errors.New("scale node group failed")
)

Common error variables used across cluster provisioner tests to avoid duplication.

Functions

func DefaultDeleteCases

func DefaultDeleteCases() []testutils.NameCase

DefaultDeleteCases returns standard test cases for testing delete operations with name handling.

func DefaultNameCases

func DefaultNameCases(cfgName string) []testutils.NameCase

DefaultNameCases returns standard test cases for testing operations with name handling.

func RunActionSuccess

func RunActionSuccess[MockT, ProvisionerT any](
	t *testing.T,
	label string,
	inputName, expectedName string,
	setupFn func(*testing.T) (ProvisionerT, MockT),
	expectFn func(MockT, string),
	actionFn func(ProvisionerT, string) error,
)

RunActionSuccess provides a generic helper for testing successful provisioner actions. It eliminates code duplication between EKS and Kind test files by abstracting the common pattern: setup -> expect -> action -> assert.

func RunCreateSuccessTest

func RunCreateSuccessTest[MockT, ProvisionerT any](
	t *testing.T,
	setupFn func(*testing.T) (ProvisionerT, MockT),
	expectFn func(MockT, string),
	actionFn func(ProvisionerT, string) error,
)

RunCreateSuccessTest provides a standard test pattern for Create operations. This eliminates duplication between EKS and Kind test files by providing the common TestCreate_Success structure that both can use. Note: The caller should call t.Parallel() for parallel execution.

func RunCreateTest

func RunCreateTest(
	t *testing.T,
	runActionSuccessFunc func(t *testing.T, inputName, expectedName string),
)

RunCreateTest runs a standard Create success test pattern with the common cfg-name cases. This centralizes the Create test pattern of: - Getting DefaultNameCases("cfg-name") - Running RunStandardSuccessTest with "Create()" action.

func RunStandardSuccessTest

func RunStandardSuccessTest(
	t *testing.T,
	cases []testutils.NameCase,
	testRunner func(t *testing.T, inputName, expectedName string),
)

RunStandardSuccessTest runs a standard success test pattern with parallel execution and name cases. This centralizes the common pattern of: - Getting test cases - Running testutils.RunNameCases with t.Helper(). Note: Caller should call t.Parallel() for parallel execution.

Types

This section is empty.

Jump to

Keyboard shortcuts

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