Skip to content

Testing workflows and actions

Orchestrator has no unit test framework, and most of what it does talks to other systems, so most testing ends up as “run it on a test VM and look”. That’s an integration test, and you need it, but it’s slow and it rarely covers the awkward cases. VMware’s Coding Design Guide suggests two more kinds of test, both written as ordinary workflows: unit tests for the logic, with no external system at all, and integration checks that prove an installation is wired up, without changing anything.

This recipe adds both to the decommissioning solution.

Getting ready

  • The decommissioning solution from recipes 9.1 and 9.4.
  • The folder VCF Orchestrator Guide/Chapter 9/99 Test (recipe 9.3).

How to do it

  1. Look at VCFG - VM - Delete Retired VMs from recipe 9.1. Most of its script talks to vCenter, but one part is pure logic: reading the last RETIRED line from a VM’s notes and deciding whether it’s valid. That’s the part with the awkward cases: no notes, other notes first, retired twice, a mangled date. Testing them on real VMs would mean building a VM for each.
  2. Move it into an action. In com.vcfguide.vm, create getRetiredInfo, with the input notes (string) and the return type Properties. It returns retiredOn and ticketId, or null:
com.vcfguide.vm/getRetiredInfo
// Pure logic: no vCenter, so it can be tested with plain strings.
var matches = (notes || "").match(/RETIRED (\S+) ticket (\S+)/g);
if (!matches) {
return null;
}
var parts = matches[matches.length - 1].split(" ");
if (isNaN(new Date(parts[1]).getTime())) {
return null;
}
var info = new Properties();
info.put("retiredOn", parts[1]);
info.put("ticketId", parts[3]);
return info;
  1. In the script of Delete Retired VMs, add var vmModule = System.getModule("com.vcfguide.vm"); before the loop, and replace the lines that parse the notes with a call to the action:
Delete Retired VMs — the loop now starts like this
for (var i = 0; i < vms.length; i++) {
var info = vmModule.getRetiredInfo(vms[i].config.annotation);
if (!info) {
System.warn("[VCFG][Delete Retired VMs] " + vms[i].name + " has no RETIRED note, skipped");
continue;
}
if (new Date(info.get("retiredOn")).getTime() > cutoff) {
System.log("[VCFG][Delete Retired VMs] " + vms[i].name + " retired " + info.get("retiredOn") + ", kept");
continue;
}
// … power state check and VCFG - LIB - Delete VM as before,
// with info.get("ticketId") in the last log line

Raise the workflow’s version to 1.1.0: its behaviour is the same, but its code changed.

B. A unit test: plain strings in, expected results out

Section titled “B. A unit test: plain strings in, expected results out”
  1. In 99 Test, create VCFG - VM - Test getRetiredInfo [TEST], with no inputs and the output passed (number). One scriptable task, Run cases, holds every case as data, runs the action on each, and fails listing the ones that broke:
VCFG - VM - Test getRetiredInfo [TEST] — Run cases
// Each case: notes in, expected retiredOn and ticketId out (null = no valid note).
var cases = [
{ name: "empty notes", notes: "", retiredOn: null },
{ name: "no notes at all", notes: null, retiredOn: null },
{ name: "one line", notes: "RETIRED 2026-12-01T13:24:19.544Z ticket CHG-0004 by vcfguide",
retiredOn: "2026-12-01T13:24:19.544Z", ticketId: "CHG-0004" },
{ name: "other notes first", notes: "Owner: web team\nRETIRED 2026-11-02T08:00:00.000Z ticket CHG-0001 by vcfguide",
retiredOn: "2026-11-02T08:00:00.000Z", ticketId: "CHG-0001" },
{ name: "retired twice, last wins", notes: "RETIRED 2026-11-02T08:00:00.000Z ticket CHG-0001 by a\nRETIRED 2026-12-01T09:00:00.000Z ticket CHG-0007 by b",
retiredOn: "2026-12-01T09:00:00.000Z", ticketId: "CHG-0007" },
{ name: "bad date", notes: "RETIRED yesterday ticket CHG-0002 by vcfguide", retiredOn: null },
{ name: "lower case", notes: "retired 2026-12-01T09:00:00.000Z ticket CHG-0003 by vcfguide", retiredOn: null }
];
var vmModule = System.getModule("com.vcfguide.vm");
var failures = [];
passed = 0;
for (var i = 0; i < cases.length; i++) {
var c = cases[i];
var info = vmModule.getRetiredInfo(c.notes);
var gotDate = info ? info.get("retiredOn") : null;
var gotTicket = info ? info.get("ticketId") : null;
if (gotDate === c.retiredOn && (c.retiredOn === null || gotTicket === c.ticketId)) {
passed++;
} else {
failures.push(c.name + ": got " + gotDate + " / " + gotTicket);
}
}
System.log("[VCFG][Test getRetiredInfo] " + passed + " of " + cases.length + " passed");
if (failures.length > 0) {
throw "[VCFG][Test getRetiredInfo] failed: " + failures.join("; ");
}
  1. Run it. It completes with passed = 7 and the log line 7 of 7 passed. Change one expected value, run it again, and check that it fails and names the case; then change it back.

C. An integration check: is this installation wired up?

Section titled “C. An integration check: is this installation wired up?”
  1. In 99 Test, create VCFG - VM - Test Decommissioning Setup [TEST], with the output report (string), and the variables retireFolder and graceDays bound to VCFG_Decommission. One scriptable task checks every piece without touching a VM, and runs the unit test too:
VCFG - VM - Test Decommissioning Setup [TEST] — Check the solution
// Read-only: checks the pieces of the solution, never touches a VM.
var lines = [];
var problems = 0;
function check(ok, text) {
lines.push((ok ? "OK " : "FAIL ") + text);
if (!ok) { problems++; }
}
// 1. Settings
check(retireFolder != null, "retireFolder is set in VCFG_Decommission");
check(graceDays >= 1, "graceDays is at least 1 (now " + graceDays + ")");
// 2. vCenter: the folder can be read with the plug-in's account
if (retireFolder) {
try {
var count = retireFolder.childEntity.length;
check(true, "retire folder " + retireFolder.name + " readable, " + count + " item(s) in it");
} catch (e) {
check(false, "retire folder not readable: " + e);
}
}
// 3. Library workflows, found by ID as their callers find them
var libraries = {
"VCFG - LIB - Retire VM": "<id of VCFG - LIB - Retire VM>",
"VCFG - LIB - Delete VM": "<id of VCFG - LIB - Delete VM>"
};
for (var name in libraries) {
check(Server.getWorkflowWithId(libraries[name]) != null, name + " present");
}
// 4. Actions, with their versions, including the shared one from com.vcfguide.core
function hasAction(moduleName, actionName) {
var module = System.getModule(moduleName); // null when the module doesn't exist
var descriptions = module ? module.actionDescriptions : [];
for (var i = 0; i < descriptions.length; i++) {
if (descriptions[i].name === actionName) {
return descriptions[i].version;
}
}
return null;
}
var actions = ["com.vcfguide.vm/powerOffVm", "com.vcfguide.vm/markVmRetired",
"com.vcfguide.vm/moveVmToFolder", "com.vcfguide.vm/deleteVm",
"com.vcfguide.vm/getRetiredInfo", "com.vcfguide.core.vc/waitForTask"];
for (var a = 0; a < actions.length; a++) {
var parts = actions[a].split("/");
var version = hasAction(parts[0], parts[1]);
check(version != null, actions[a] + (version ? " " + version : " missing"));
}
// 5. The unit test
var unitTest = Server.getWorkflowWithId("<id of VCFG - VM - Test getRetiredInfo [TEST]>");
if (unitTest) {
var token = unitTest.execute(new Properties());
var deadline = new Date().getTime() + 60000;
while ((token.state === "running" || token.state === "waiting") && new Date().getTime() < deadline) {
System.sleep(1000);
}
check(token.state === "completed", "unit test VCFG - VM - Test getRetiredInfo [TEST]: " + token.state);
} else {
check(false, "unit test workflow present");
}
report = lines.join("\n");
System.log("[VCFG][Test Decommissioning Setup]\n" + report);
if (problems > 0) {
throw "[VCFG][Test Decommissioning Setup] " + problems + " check(s) failed";
}
  1. Run it. Every line of report starts with OK, and the action lines show their versions, such as OK com.vcfguide.vm/getRetiredInfo 1.0.0.
Figure 9.7. The integration check after an installation: one line per piece of the solution.
  1. End to end, the solution needs real VMs: one with an old RETIRED note, one retired today, and one with other notes only. In the lab, three empty VMs with no disks are enough; give them the notes in the vSphere Client and leave them off. Put them in vcfguide-retired and run Delete Retired VMs. Only the first is deleted; the log says why the other two were kept or skipped.
Checked on an embedded Orchestrator 9.1.1, inside VCF Automation, 1 Dec 2026. typeof System.getModule(“…”).someAction is “object”, not “function”, so check for an action with actionDescriptions. System.getModule() returns null for a module that doesn’t exist.

How it works

Sever the logic from the system. The guide’s example is a datastore renamed with a -DECOM suffix within 42 characters: the clash rules are hard, testing them on real datastores is impractical, and the rename itself is the easy part. Its answer is a workflow that takes the current name and the list of existing names, and returns the new name. getRetiredInfo does the same for notes. The test needs no vCenter, runs in a second, and covers cases you’d never set up by hand.

Tests that check, not tests that print. A test that logs results for a person to read is a demo. Run cases compares every result with the expected one and throws if any differ, so a test run is either completed or failed, and a pipeline or a scheduled run can tell which (recipes 7.2 and 7.7).

No test switches in real workflows. The guide warns against a test input that sends a workflow down a different path: you’d be testing the path production doesn’t take. The tests here call the same action and the same workflows by ID that the solution uses.

Check the wiring after every import. Most failures after a move aren’t bugs, they’re setup: an element without values, a missing shared package, a folder the plug-in’s account can’t read, a password that was rotated. The integration check finds all of these in a second, without changing anything, so it’s safe to run in production right after an import.

Mock modules for the rest. The guide goes one step further: if every call to an external system is an action in one module, a test can use a copy of that module whose actions don’t really call anything, and run the business logic above it unchanged. It’s worth it for solutions with many external calls; for this one, the test VMs in part D are simpler.

Back in vRO 5.5–7No framework, so the guide suggested test workflows that throw on a mismatch, a separate test package in source control, and mock action modules.
In Orchestrator 9.xStill no built-in framework in Orchestrator 9.x. The same test workflows work, and the REST API (recipe 7.2) or a pipeline can run them after every import and fail the deployment when one fails.

See also