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.
1. 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"
2. Usage in Test Suites
To use the data, register the plugin and the source file, then reference the dataset name in your operations.
plugins:
- name: data
sources:
- name: test-data
path: dataset.yaml
operations:
get_product:
target: oas:getProductByID
dataset: "product" # References the name in the dataset file
parameters:
path:
id: ${product:products.product10.id} # Injects '10'
3. 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 value10. - Objects:
products.product10returns the entire key-value map for that product. - Full Lists:
productsreturns 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.