Data Plugin
The data plugin allows you to define reusable datasets in YAML format to be injected into your Drift test operations. This promotes clean, data-driven testing without duplicating values across multiple files.
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.
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.yamlDefining 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"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'Supported Expressions
The Data plugin supports powerful dot-notation and function-based expressions for retrieving data.
Attributes and Collections
Attributes:
products.product10.idreturns the primitive value 10.Objects:
products.product10returns the entire key-value map for that product.Full Lists: products returns an array of all products in the dataset.
Wildcard Plucking:
products.*.idreturns 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.