testutils

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: 11 Imported by: 0

README

cmd/internal/testutils

This package provides testing utilities specifically for command-layer testing in KSail.

Purpose

Contains command-specific testing helpers, utilities, and shared test errors designed for testing CLI commands and command-layer functionality. This package provides command-layer specific testing functionality that complements the general-purpose testing utilities.

Features

  • Command Testing Helpers: Utilities for testing CLI commands and interactions
  • Mock Configuration: Helper functions for creating test configuration managers
  • Error Handling: Shared test errors for consistent command testing
  • Cobra Integration: Testing utilities for Cobra CLI commands
  • Snapshot Testing: Integration with snapshot testing for command outputs

Usage

import "github.com/devantler-tech/ksail-go/cmd/internal/testutils"

// Create a default config manager for testing
configManager := testutils.CreateDefaultConfigManager()

// Use in command tests for consistent testing setup
func TestCommand(t *testing.T) {
    // Command-specific test utilities
}

Key Components

  • helpers.go: Core testing helper functions for command testing
  • errors.go: Shared test errors for command validation
  • doc.go: Package documentation and overview

This package ensures consistent and reliable testing patterns across all KSail CLI commands.


⬅️ Go Back

Documentation

Overview

Package testutils provides testing helpers for command testing (command-layer specific).

This package contains testing utilities and shared test errors specifically designed for command tests, providing command-layer specific functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateConfigManagerWithFieldSelectors

func CreateConfigManagerWithFieldSelectors(
	writer io.Writer,
	fieldSelectors ...configmanager.FieldSelector[v1alpha1.Cluster],
) *configmanager.ConfigManager

CreateConfigManagerWithFieldSelectors creates a config manager with the provided field selectors.

func CreateDefaultConfigManager

func CreateDefaultConfigManager() *configmanager.ConfigManager

CreateDefaultConfigManager creates a standard config manager for cmd tests that passes KSail validation.

func SetupCommandWithOutput

func SetupCommandWithOutput() (*cobra.Command, *bytes.Buffer)

SetupCommandWithOutput creates a standard cobra command with output buffer for cmd tests.

func TestCmdExecuteInCleanDir

func TestCmdExecuteInCleanDir(t *testing.T, cmdFactory func() *cobra.Command, cmdName string)

TestCmdExecuteInCleanDir executes a command in a temporary directory with no ksail.yaml file and validates that it returns a configuration validation error.

func TestSimpleCommandCreation

func TestSimpleCommandCreation(t *testing.T, data SimpleCommandTestData)

TestSimpleCommandCreation tests command creation with common pattern.

func TestSimpleCommandExecution

func TestSimpleCommandExecution(t *testing.T, data SimpleCommandTestData)

TestSimpleCommandExecution tests command execution with common pattern.

func TestSimpleCommandHelp

func TestSimpleCommandHelp(t *testing.T, data SimpleCommandTestData)

TestSimpleCommandHelp tests command help output with common pattern.

func WriteValidKsailConfig

func WriteValidKsailConfig(t *testing.T, dir string)

WriteValidKsailConfig writes a minimal but valid KSail configuration into the provided directory.

Types

type SimpleCommandTestData

type SimpleCommandTestData struct {
	CommandName   string
	NewCommand    func() *cobra.Command
	ExpectedUse   string
	ExpectedShort string
}

SimpleCommandTestData holds test data for simple command testing.

Jump to

Keyboard shortcuts

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