Writing tests with workflows
Testing
In order to test this new functionality, we'll update the existing ./workflows/e2e.yaml
workflow file to include the new methods we've added (setIpfsData
, and getIpfsData
).
Add the following case to the e2e.yaml
workflow in the ./workflows
folder.
case2:
steps:
- uri: fs/build
method: setIpfsData
args:
options:
address: "$cases.0.data"
data: "Hello from IPFS!"
ipfsProvider: "http://localhost:5001"
- uri: fs/build
method: getIpfsData
args:
address: "$cases.0.data"
ipfsProvider: "http://localhost:5001"
Once our workflow has been defined, we may want to be able to validate our actual results against our expectations. Workflow validation uses CUE, a flexible and expressive data validation language. CUE must be installed to complete this step.
If you don't want to install anything right now, don't worry! Our results will be easy to verify with manually.
To continue with automated testing, let's add our expected output to a new file in the workflows folder. We will call
the file validator.cue
.
package e2e
cases: {
$0: {
data: =~"^0x[A-Fa-f0-9]{40}$",
error?: _|_, // Never fails
}
case1: {
$0: {
data: =~"^0x[A-Fa-f0-9]{64}$",
error?: _|_,
}
$1: {
data: uint,
error?: _|_
}
}
case2: {
$0: {
data: {
txReceipt: string,
ipfsHash: "QmPhAJz5QbidN3LgT2eDiu6Z3nCFs2gYQMbjgEAncrGsis"
},
error?: _|_,
}
$1: {
data: "Hello from IPFS!",
error?: _|_,
}
}
}
With our workflow complete, we'll deploy and test our wrap locally in the next section!