file contents test regex seems to not be working properly
chris-ratcliffe opened this issue · comments
Hello. I have the following 2 tests defined:
fileContentTests:
- name: 'hosts check'
path: '/etc/hosts'
expectedContents: [".*127.*"]
commandTests:
- name: "check hosts"
command: "cat"
args: ["/etc/hosts"]
expectedOutput: [".*127.*"]
exitCode: 0
In reality, they do the same thing. Make sure the string 127 exists somewhere in the /etc/hosts file. The command test works fine, but the file content test errors out with:
=== RUN: File Content Test: hosts check
--- FAIL
duration: 0s
Error: Expected string '.*127.*' not found in file content string ''
Am I misusing the regex in the content test check? The fact that the error message seems to indicate that the file content string is empty is suspicious.
I am using version 1.10.
I think this is a problem with containers in general, they generate /etc/hosts
at run time (for Linux distros at least). I did some googling and came across this SO answer which gives a clearer answer to why this happens.
FWIW, I fired up dive on a debian
based image and indeed /etc/hosts
is an empty file:
To further verify, running a fresh debian
image and looking at /etc/hosts
you can see it's recreated at run time:
So, I think the most straightforward approach would be to use your commandTests
.