Running Rego Tests in Jenkins Pipeline - jenkins

I am trying to run rego test cases as part of jenkins pipeline run. I previously had my test case and the input data for the test case in a single file and they all ran successfully.
I modified my test cases to read the data from an external json file and the current folder structure is as follows: test.rego file and input.json file in same folder.
This is what I use in Jenkins to run the tests *./opa test -b -v .*
The tests are failing with the error data.utilities.test_no_OwnerContact: FAIL
I am assuming this is because the rego test is unable to read the data from input.json
When I am trying to pass the input file explicitly using -i/--input, I see an error in jenkins as Error: unknown flag: --input
I am not sure if I am using the required tags or if it is something else.
Any help would be appreciated.
Thanks!
Edit: I printed the files in the bundle, and I see the data.json file present. So the OPA engine is not able to read the data file from the Bundle. How can I fix this issue?

The way you'd specify input data in tests is not with an input.json file, but by mocking the input using the with .. as construct. An example test mocking input might look something like this:
test_with_mocked_input {
allow with input as {
"deployment_name": "testing",
"replicas": 2
}
}
See the docs on data mocking for further info.

Related

PyCharm: Unit testing directory setup with remote interpreter

For years I've been running a Docker container on my local machine and using it as a remote Python interpreter via SSH in PyCharm. This works great (though 2022.2.1 brought a lot of new bugs that have been slowly being ironed out) for running my code! I'm now on 2022.2.3.
However, I'm having issues running unit tests. In the past (i.e. before version 2022.2.1), I could simply right click my tests directory (a direct child of my main project directory) and click Run Python tests in test... and it would all work as expected.
Now, though, when I click this, I receive an error message about "No such file or directory."
I've tried everything I can think of- I've setup my path mappings in the Python test run config to exactly match those shown in my Python run config, and have tried every version of directory and subdirectory in the mappings and working directory, but I always receive an error about either having an empty test suite (no tests found), or that the directory "must be in the project."
It seems like no matter what I do, PyCharm is trying to create a temp directory somewhere, or is trying to read from some temp directory that I never specified, because I see errors this like:
AssertionError: /tmp/pycharm_project_405/docker/tests: No such file or directory
Yet I never created, specified, or requested a temp directory of any sort, let alone one named /tmp/pycharm_project_405/; this is a mystery to me.
PyCharm with an SSH interpreter is rapidly becoming unusable for me and my team because we cannot figure out how to set this up. Can anybody please offer some guidance on what we need to do?
Thank you all so very much!
I tried:
Changing run config for Python tests to match the working directory and path mapping of Python run configs (which work)
Directly specifying the path to the tests from the container's perspective
Setting up run config templates
Specifying one directory up/down from the actual tests
Expected:
Unit tests to be found and run as they were in previous versions of PyCharm
Answer
Create a run config for testing
In the testing run config, set Target: to Custom
Set the correct remote interpreter
Set Working directory to the test folder
Set TWO path mappings: 1) Map the code directory (in my case, the parent directory of the tests folder) and 2) Map the test directory itself
Voila!!!

How does AOSP build system produce .rsp files and how to get them?

According to How does AOSP 9.0 build system link the executable? and What does # mean in this clang command in AOSP build log? , when linking a module, AOSP seems to produce a .rsp file that contains all the obj files that the module need,and pass the file name as a parameter to the link command, for example:
prebuilts/clang/host/linux-x86/clang-4691093/bin/clang++ /OpenSource/Build/Android/9.0.0_r30/soong/.intermediates/bionic/libc/crtbegin_so/android_x86_64_core/crtbegin_so.o #/OpenSource/Build/Android/9.0.0_r30/soong/.intermediates/frameworks/base/libs/hwui/libhwui/android_x86_64_core_shared/libhwui.so.rsp ......
But the .rsp files seems to be removed after build.
The question is, how are these file generated and how to get these files? This may require to learn and modify the build scripts which is out of reach for me.
There maybe the answer for you, read the ninja build manual , in that manual .rsp file mentioned.
https://ninja-build.org/manual.html
the following is info that I copy out.
rspfile, rspfile_content
if present (both), Ninja will use a response file for the given command, i.e. write the selected string (rspfile_content) to the given file (rspfile) before calling the command and delete the file after successful execution of the command.
This is particularly useful on Windows OS, where the maximal length of a command line is limited and response files must be used instead.

Writing file out of bazel test [duplicate]

I'm running E2E test using some bazel test target (the scala flavour of java_test).
In Maven I used to dump logs to target/logs folder that was created during test time, and then if something failed - I could have looked in this folder and find the logs.
In bazel - what path can I put in my test logs configuration so it would be writable and conveniently available upon test finish / test failure?
I know that the java.io.tmp dir is writable but gets deleted immediately after test finishes.
So digging through bazel docs I found this:
https://docs.bazel.build/versions/master/test-encyclopedia.html#initial-conditions
Seems like I can read env variable "TEST_UNDECLARED_OUTPUTS_DIR" and it will give me a writable path. Anything I write there would be zipped and saved under ./bazel-out/darwin-fastbuild/testlogs/<package-name>/<target-name>/test.outputs/outputs.zip
Pretty cool!
You can set a writable path for bazel test by using the environment variable TEST_TMPDIR="<.file directory.>".

Getting fatal error during transformation while running JMETER script through ANT

I have a Jmeter script which downloads pdf from an application. The script works perfectly fine when I run the script through JMETER GUI (Screenshot 1). Also, I am able to see the generated pdf in Response section (Screenshot 1).
Screenshot 1
But when I try to run the same script through ANT(Build.xml), the script is getting failed with the below error (Screenshot 2).
BUILD FAILED
E:\Apache\apache-jmeter-3.2\extras\build.xml:128: Fatal error during transformat
ion using E:\Apache\apache-jmeter-3.2\extras\jmeter-results-detail-report_21.xsl
: Character reference "&#x14" is an invalid XML character.; SystemID: file:/E:/A
pache/apache-jmeter-3.2/extras/Overview.jtl; Line#: 332772; Column#:
25
Screenshot 2
Is there something extra I need to add in Build.xml to generate pdf through ANT? The script is failing when jtl file is transforming into html file. The script is unable to generate html report because of invalid characters in jtl file.
Can someone help me with this.
I have created a sample script which downloads pdf. Please find the script in the below link.
JMX script which downloads pdf
The above script is working fine when I run through JMETER GUI
(screenshot 3)
Screenshot 3.I am able to see generated pdf in response section.
But when I run the same script through Ant, I am getting below error(screenshot 4).
Screenshot 4
Most probably .jtl results file is corrupt due to unescaped &#x14 character. If you are storing response data in .jtl file - please don't as it causes massive disk IO and might have negative impact on your test.
Try running your script like:
ant -Dshow-data=n ...
Or locate the following line in build.xml file:
<property name="jmeter.save.saveservice.response_data.on_error" value="${funcMode}"/>
and amend it to be
<property name="jmeter.save.saveservice.response_data.on_error" value="false"/>
References:
JMeter Properties Reference: Results File Config
Five Ways To Launch a JMeter Test without Using the JMeter GUI

jacaco unit test coverage reports path and file name(as jacaco.exec)

I am running following maven command on jenkins
clean org.jacoco:jacoco-maven-plugin:prepare-agent install
The jacaco exec file created as shown below.
target/coverage-reports/jacoco-int-test.exec
I would like to generate this file under following path, since all other Project use same conventions.
target/jacoco.exec
I could not figureout why it is generated in this way and how to modify it as "target/jacoco.exec"
I will use this report in sonarqube analysis.
I would appriciate your helps, thanks in advance.
As per documentation of prepare-agent - destFile parameter controls location of output file, whose default is ${project.build.directory}/jacoco.exec which is exactly target/jacoco.exe. So check your POMs to find where it is modified to be target/coverage-reports/jacoco-int-test.exec.

Resources