Skip to main content

templates_test.go

templates_test.go - Overview

This file contains unit tests for the template expansion functionality used in alert rule processing. It specifically tests the TemplateExpander to ensure that it correctly substitutes values into templates based on provided data.

Detailed Documentation

TestTemplateExpander

  • Purpose: Tests the basic functionality of the TemplateExpander by providing a simple template and data, and verifying that the expansion produces the expected result.
  • Parameters:
    • t (*testing.T): Testing object for running the test case.
  • Returns: None

TestTemplateExpander_WithThreshold

  • Purpose: Tests the TemplateExpander with a template that includes a threshold value. Verifies that the threshold value is correctly substituted into the template.
  • Parameters:
    • t (*testing.T): Testing object for running the test case.
  • Returns: None

TestTemplateExpanderOldVariableSyntax

  • Purpose: Tests the TemplateExpander with old variable syntax i.e. {{.Labels.service_name}}.
  • Parameters:
    • t (*testing.T): Testing object for running the test case.
  • Returns: None

TestTemplateExpander_WithAlreadyNormalizedKey

  • Purpose: Tests the TemplateExpander with already normalized key in labels i.e. service_name instead of service.name.
  • Parameters:
    • t (*testing.T): Testing object for running the test case.
  • Returns: None

TestTemplateExpander_WithMissingKey

  • Purpose: Tests the TemplateExpander's behavior when a key is missing from the provided data. It asserts that the missing key is handled gracefully (resulting in an empty string).
  • Parameters:
    • t (*testing.T): Testing object for running the test case.
  • Returns: None

TestTemplateExpander_WithLablesDotSyntax

  • Purpose: Tests the TemplateExpander with labels containing dot syntax.
  • Parameters:
    • t (*testing.T): Testing object for running the test case.
  • Returns: None

TestTemplateExpander_WithVariableSyntax

  • Purpose: Tests the TemplateExpander with a template using variable syntax like {{$service.name}}.
  • Parameters:
    • t (*testing.T): Testing object for running the test case.
  • Returns: None

Code Examples

None

Include in Getting Started: NO