Skip to content

Commit

Permalink
config test: use acbgrep
Browse files Browse the repository at this point in the history
Use acbgrep, in order to provide better error messages when `grep`
fails.

Signed-off-by: Alex Couture-Beil <[email protected]>
  • Loading branch information
alexcb committed Nov 27, 2023
1 parent 1796754 commit 4bf1603
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tests/config/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test:
COPY expected-*.yml .

# Ensure earthly doesn't create overridden config files when they don't exist
RUN earthly --config config.yml config global.disable_analytics true 2>&1 | grep 'failed to read from config.yml: open config.yml: no such file or directory'
RUN earthly --config config.yml config global.disable_analytics true 2>&1 | acbgrep 'failed to read from config.yml: open config.yml: no such file or directory'

RUN touch config.yml

Expand Down Expand Up @@ -98,15 +98,15 @@ test:
# check permission error is correctly returned
COPY hello.earth Earthfile
RUN ! earthly --config=/tmp/config.yml --verbose +hello > output.txt 2>&1
RUN cat output.txt | grep 'Error: read config: failed to read from /tmp/config.yml: open /tmp/config.yml: permission denied'
RUN cat output.txt | acbgrep 'Error: read config: failed to read from /tmp/config.yml: open /tmp/config.yml: permission denied'

# check permission error is correctly returned even when earthly attempts to read from the default location
# to make this test work, a symbolic link is required (chown root:root /home/testuser/.earthly/config.yml doesnt work)
RUN rm /home/testuser/.earthly/config.yml
RUN ln -s /tmp/config.yml /home/testuser/.earthly/config.yml

RUN ! earthly --verbose +hello > output.txt 2>&1
RUN cat output.txt | grep 'Error: read config: failed to read from /home/testuser/.earthly/config.yml: open /home/testuser/.earthly/config.yml: permission denied'
RUN cat output.txt | acbgrep 'Error: read config: failed to read from /home/testuser/.earthly/config.yml: open /home/testuser/.earthly/config.yml: permission denied'

# make it obvious that this test passed, due to the previous grep displaying "Error: ..." when it passes
RUN echo "config test passed"
Expand Down

0 comments on commit 4bf1603

Please sign in to comment.