landro / TesTcl

when you don't have the balls to test your F5 BIG-IP iRules directly in production
https://testcl.com
BSD 3-Clause "New" or "Revised" License
98 stars 30 forks source link

Return code != 0 when tests are failing #69

Open axel3rd opened 2 years ago

axel3rd commented 2 years ago

First of all, thanks for your work. TesTcl is wonderful for accelerating & testing F5 iRules 😍.

A common practice in CI pipelines is to fail build when tests are failing (on pull request for sample). An easy way is to use the return code of test command, which is a default behavior when result is != 0.

I'm trying to achieve it without success. I agree a trick could be to analyze the output log, but less beautiful way.

Snippet for reproduction:

# File: sample.tcl
rule sample {

  when HTTP_REQUEST {
    HTTP::header replace "Some-Header" "FooBar"
  }
}
# File: test_sample.tcl
package require -exact testcl 1.0.14

namespace import ::testcl::*

it "should fail" {
  event HTTP_REQUEST
  verify "Header added" "FooBar" eq {HTTP::header "Some-Header"}
  verify "Header does not exist should fail" "No Value" eq {HTTP::header "Header-Not-Exist"}
  run sample.tcl sample
}

Command execution (Using #51, really useful ... and problem seems not linked to Docker):

$ docker run -it --rm -v $(pwd):/app jones2748/docker-testcl jtcl /app/test_sample.tcl

**************************************************************************
* it should fail
**************************************************************************
verification of 'Header added' done.
-> Test failure!!
-> -> Verification 'Header does not exist should fail' failed - expression: {No Value} eq {}
error     Verification 'Header does not exist should fail' failed - expression: {No Value} eq {}

$ echo $?
0

Is it a way to achieve it with TesTcl or the problem is in used components (like jtcl ... not active project since 7 years ... so perhaps less easy 😢).

Many thanks.