Skip to main content

Data Plugin

The Data plugin allows you to define reusable datasets in YAML format and inject them into your Drift test operations. This promotes clean, data-driven testing without duplicating values across test cases.

1. When to Use This Plugin

Use the Data plugin when you want to separate test data from test logic, or when multiple test operations share the same data values.

2. Registering the Plugin

Add the plugin to the plugins section and register your dataset file as a source:

plugins:
- name: data

sources:
- name: test-data
path: dataset.yaml

3. Defining a Dataset

Create a YAML file with the drift-dataset-file: V1 header. Data is organized into named datasets.

# dataset.yaml
drift-dataset-file: V1
datasets:
- name: product
data:
products:
product10:
id: 10
type: "beverage"
price: 10.99
name: "cola"
version: "1.0.0"

4. Using Datasets in Test Operations

Reference the dataset name in your operations, then use dot-notation expressions to inject specific values.

operations:
get_product:
target: oas:getProductByID
dataset: "product" # References the name in the dataset file
parameters:
path:
id: ${product:products.product10.id} # Injects '10'

5. Supported Expressions

The Data plugin supports powerful dot-notation and function-based expressions for retrieving data.

Attributes and Collections

  • Attributes: products.product10.id returns the primitive value 10.
  • Objects: products.product10 returns the entire key-value map for that product.
  • Full Lists: products returns an array of all products in the dataset.
  • Wildcard Plucking: products.*.id returns a list of all IDs (e.g., [10]).

The notIn Function

Generate a random value that is guaranteed not to be in a specified set. This is ideal for testing negative scenarios like 404 Not Found.

# Generates a random value that is NOT 10
id: ${product:notIn(products.*.id)}

Note: This only works with primitive values and will match the type of the first item in the set.