crc-org / crc

CRC is a tool to help you run containers. It manages a local OpenShift 4.x cluster, Microshift or a Podman VM optimized for testing and development purposes
https://crc.dev
Apache License 2.0
1.26k stars 242 forks source link

[TEST] testsuite's shell library doesn't parse command output correctly if it doesn't end with newline #4416

Closed rohanKanojia closed 2 weeks ago

rohanKanojia commented 4 weeks ago

Component

E2E Test Utilities

Description

Related to https://github.com/crc-org/crc/issues/4397

I encountered this issue while working on https://github.com/crc-org/crc/issues/4397 . I had two statements in my test feature file where I just curl application endpoint and verify whether we received expected response:

Then executing "curl -s http://quarkus-jkube-quarkus-app-deploy-flow-test.apps-crc.testing" succeeds
And stdout should contain "{\"applicationName\":\"JKube\",\"message\":\"Subatomic JKube really whips the llama's ass!\"}"

However, I was getting the actual output string as '', hence causing the assertion to fail.

On closer look to shell.go , it looks like we append a token of the command's exit code to command stdout. We split the command output by \n and expect the last line containing the exit code token exitCodeOfLastCommandInShell= .

Here while parsing command output we either write command output or exit code: https://github.com/crc-org/crc/blob/9b7772df66f32d336106b7f0144abf79eb080e94/test/extended/util/shell.go#L94-L99

This works for most cases, however the application I was testing E2E test with didn't had output ending with a newline. So we were getting a line like this:

{"applicationName":"JKube","message":"Subatomic JKube really whips the llama's ass!"}exitCodeOfLastCommandInShell=0

Due to this command output was being ignored.

We should refactor this code to also extract any prefix before exit code token and also write it to output buffer.

Expected Behavior

Shell command should be correctly parsed regardless of whether it ends with newline or not

Acceptance Criteria