确定测试厨房测试是通过还是失败

Determining if a test-kitchen test passed or failed

我们有一个看起来像这样的脚本:

#!/bin/bash
for cookbook in $cookbooks; do
    cd /path/to/$cookbook
    kitchen test;
    # Log whether the test failed or passed
done;

# Print number of tests passed and number of tests failed

如何确定我的 kitchen test 是通过还是失败?

您可以检查 kitchen test 命令的退出状态,并像这样递增计数器:

#!/bin/bash
let failed=0
let passed=0

for cookbook in $cookbooks; do
  cd /path/to/$cookbook
  kitchen test;

  if [ $? -ne 0 ]
  then
     failed=$((failed + 1))
  else
    passed=$((passed + 1))
  fi
done;

echo "There was $passed passed and $failed failed tests."