Module 6: Testing and Debugging

Overview

Now that you can build sophisticated operators with webhooks (Module 5), it’s time to learn how to test and debug them effectively. This module covers unit testing with envtest, integration testing, debugging techniques, and observability patterns that make operators production-ready.

Duration: 6-7 hours
Prerequisites:

Learning Objectives

By the end of this module, you will:

  • Write comprehensive unit tests using envtest
  • Create integration test suites with Ginkgo/Gomega
  • Debug operators effectively using Delve and logs
  • Add observability with metrics, logging, and events
  • Understand testing best practices for operators

Module Structure

  1. Lesson 6.1: Testing Fundamentals
  2. Lesson 6.2: Unit Testing with envtest
  3. Lesson 6.3: Integration Testing
  4. Lesson 6.4: Debugging and Observability

Prerequisites Check

Before starting, ensure you’ve completed:

  • Module 5: Operator with webhooks
  • ✅ Understand Go testing from Module 2
  • ✅ Have a working operator from Module 3/4/5
  • ✅ Basic understanding of Go testing (go test)

If you haven’t completed Module 5, start with Module 5: Webhooks and Admission Control.

What You’ll Build

Throughout this module, you’ll add testing and observability to your Database operator:

  • Unit tests for reconciliation logic
  • Integration tests for end-to-end scenarios
  • Debugging setup for local development
  • Metrics and logging for observability

Setup

Before starting this module:

  1. Have your Database operator from Module 3/4/5:
    • Should have a working operator
    • Webhooks implemented (from Module 5)
    • Ready to add tests
  2. Ensure development environment is ready:
    ./scripts/setup-dev-environment.sh
    
  3. Install testing tools:
    # Install Ginkgo and Gomega
    go install github.com/onsi/ginkgo/v2/ginkgo@latest
       
    # Install Delve debugger
    go install github.com/go-delve/delve/cmd/dlv@latest
    

Hands-on Labs

Each lesson includes hands-on exercises that add testing and observability to your operator.

Solutions

Complete working solutions for all labs are available in the solutions directory: