Mapping

A mapping is a set of key-value pairs that associates each key with a value, used in YAML, JSON, and other configuration formats to structure settings, parameters, and secrets.

Table of Contents

Table of Contents

How mappings work

A mapping expresses a relationship between associated values, usually as key-value pairs. In YAML, a key named environment might hold two nested keys, DATABASE_URL and LOG_LEVEL, each with its own value.

Mappings define structured data in declarative systems such as Kubernetes, Helm, and CI/CD pipelines.

  • Keys: unique names, such as DATABASE_URL
  • Values: strings, numbers, lists, or other mappings
  • Nesting: mappings can contain other mappings for structure
  • Common names: also called dictionaries, hashes, or objects

Mappings vs. arrays

Configuration files use both. They store data in different shapes.

Mapping Array (sequence)
Structure Key-value pairs Ordered list of items
Access By key name By position
YAML example LOG_LEVEL: debug - item-one
Best for Named settings Repeated items, such as containers

Why mappings matter in configuration and testing

Mappings give configuration files their structure. In testing, they control inputs, credentials, and settings across environments.

  • Clarity: configuration files are easier to read and manage
  • Parameterization: reusable templates swap in values dynamically
  • Environment customization: separate mappings for dev, staging, and production
  • Consistency: fewer manual errors in repeated configurations
  • Secret management: map variables to sensitive values without hardcoding them

Consider a SaaS team that runs one API suite against three environments. A mapping per environment changes only the base URL and key. The tests stay identical.

Common challenges with mappings

  • Indentation errors: YAML and JSON mappings break on small syntax mistakes
  • Override conflicts: several mappings set the same key to different values
  • Secret exposure: sensitive values stored in plain text
  • Environment drift: inconsistent mappings across clusters or teams
  • No validation: invalid mappings break deployments or test runs

Validate mappings with schemas, encrypt sensitive values, and keep configurations in version control.

How mappings relate to Testkube

Testkube uses mappings to define test parameters, environment variables, and secrets. Tests stay modular, reproducible, and environment-agnostic.

  • Configuration mappings: test-level parameters such as URLs, tokens, or timeouts
  • Secret mappings: references to Kubernetes Secrets, resolved at runtime
  • Execution mappings: inputs such as environment or test type that shape each run
  • Workflow mappings: relationships between test steps, dependencies, or outputs
  • Result mappings: test outputs linked to reports, dashboards, or observability tools

Real-world examples

  • Multi-environment tests: a QA engineer maps API_KEY and BASE_URL to run one suite in every environment
  • Secure secrets: a DevOps team stores sensitive mappings as Kubernetes Secrets referenced by Testkube
  • Helm values: a developer customizes Testkube behavior per environment in a values file
  • Dashboards: a platform engineer maps workflow variables to Grafana dashboards

Frequently Asked Questions (FAQs)

How are mappings different from arrays in configuration files?

Mappings store named key-value pairs. Arrays store ordered lists accessed by position.

Can mappings contain other mappings?

Yes. Nested mappings are common in Kubernetes manifests and Helm values files.

Are mappings the same as dictionaries or hashes?

Yes. Different languages use different names for the same key-value structure.

How do I secure sensitive values in mappings?

Store them in Kubernetes Secrets or a secrets manager. Reference them instead of writing values in plain text.

What is the best way to validate mapping syntax?

Use a YAML linter or schema validation in CI. Catch errors before deployment or test runs.

Can Testkube mappings be environment variables?

Yes. Testkube can map values to environment variables in each test run, including values from Secrets.

Related Terms and Concepts

No items found.