0

I wrote some tests which should fail (return 1). If I redirect the error to /dev/null will the pipeline break? Should this work in Github actions?

if [ -d "failing_tests" ]; then
   for test in failing_tests/*
   do
       helm lint --strict --values "$test" > /dev/null 2>&1
       exit_code=$?
       if [ $exit_code -ne 1 ]; then
           echo "failing test passed (error)"!
           mv "_values.yaml" "values.yaml"
           exit 1
       fi
       nr_tests=$((nr_tests+1))  
   done
fi

(I renamed the values.yaml)

runs-on: ubuntu-latest

This is how the entire step looks like:

  - name: Running the unit tests
    run: |
      find charts -name "values.schema.json" -exec dirname {} \; |  
        while read directory; do
        cd "$directory"
        nr_tests=0
        mv "values.yaml" "_values.yaml"
        if [ -d "passing_tests" ]; then
            for test in passing_tests/*
            do
                helm lint --values "$test" > /dev/null 2>&1
                exit_code=$?
                if [ $exit_code -ne 0 ]; then
                    echo "passing test: $test failed (error)"!
                    mv "_values.yaml" "values.yaml"
                    exit 1
                fi
                nr_tests=$((nr_tests+1))
            done

        fi
        if [ -d "failing_tests" ]; then
            for test in failing_tests/*
            do
                helm lint --strict --values "$test" > /dev/null 2>&1
                exit_code=$?
                if [ $exit_code -ne 1 ]; then
                    echo "failing test passed (error)"!
                    mv "_values.yaml" "values.yaml"
                    exit 1
                fi
                nr_tests=$((nr_tests+1))  
            done
        fi
        mv "_values.yaml" "values.yaml"
        cd - > /dev/null
        echo "$nr_tests (all) tests in $directory succeed"
        done

I have no problem with the passing tests.

Azeem
  • 11,148
  • 4
  • 27
  • 40
  • Are you using this directly under `run`? What does your step look like? Please include your relevant workflow in your question, specifically `runs-on` and the step where the above snippet executes. – Azeem May 17 '23 at 06:54
  • **If I redirect the error to /dev/null will the pipeline break?** - yes, this should fail. – Azeem May 17 '23 at 07:10
  • See [`jobs..steps[*].shell`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell) for the default flags. – Azeem May 17 '23 at 07:11
  • Relevant: https://stackoverflow.com/questions/75419587/does-a-github-action-step-use-set-e-semantics-by-default – Azeem May 17 '23 at 07:12
  • Redirection by itself does not influence the return code of a program. It is conceivable that a mischievous programmer writes a program which detects, whether stderr is redirected, and adjusts the exit code accordingly. In this case, I would fire the programmer instead of fixing the pipeline.... – user1934428 May 17 '23 at 07:14

0 Answers0