Skip to content

Commit

Permalink
Add newline to each stdout line from ansible output (#421)
Browse files Browse the repository at this point in the history
* Add newline to each stdout line from ansible output
[RHCLOUD-36644]
  • Loading branch information
dehort authored Dec 9, 2024
1 parent 708cb3b commit ef900cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions internal/common/ansible/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func GetStdout(events []messageModel.PlaybookRunResponseMessageYamlEventsElem, h

if event.Stdout != nil {
result += *event.Stdout
if event.EndLine > event.StartLine {
result += "\n"
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/common/ansible/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ var _ = Describe("Ansible", func() {
It("determines stdout from a successful run", func() {
events := loadFile("./test-events1.jsonl")
stdout := GetStdout(events, nil)
Expect(stdout).To(Equal("\r\nPLAY [ping] ********************************************************************\r\nTASK [ping] ********************************************************************\x1b[0;32mok: [localhost]\x1b[0m\r\nPLAY RECAP *********************************************************************\r\n\x1b[0;32mlocalhost\x1b[0m : \x1b[0;32mok=1 \x1b[0m changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \r\n"))
Expect(stdout).To(Equal("\r\nPLAY [ping] ********************************************************************\n\r\nTASK [ping] ********************************************************************\n\x1b[0;32mok: [localhost]\x1b[0m\n\r\nPLAY RECAP *********************************************************************\r\n\x1b[0;32mlocalhost\x1b[0m : \x1b[0;32mok=1 \x1b[0m changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \r\n\n"))
})

It("determines stdout from a failed run", func() {
events := loadFile("./test-events2.jsonl")
stdout := GetStdout(events, nil)
Expect(stdout).To(Equal("\r\nPLAY [ping] ********************************************************************\r\nTASK [fail] ********************************************************************\x1b[0;31mfatal: [localhost]: FAILED! => {\"changed\": false, \"msg\": \"Always fail\"}\x1b[0m\r\nPLAY RECAP *********************************************************************\r\n\x1b[0;31mlocalhost\x1b[0m : ok=0 changed=0 unreachable=0 \x1b[0;31mfailed=1 \x1b[0m skipped=0 rescued=0 ignored=0 \r\n"))
Expect(stdout).To(Equal("\r\nPLAY [ping] ********************************************************************\n\r\nTASK [fail] ********************************************************************\n\x1b[0;31mfatal: [localhost]: FAILED! => {\"changed\": false, \"msg\": \"Always fail\"}\x1b[0m\n\r\nPLAY RECAP *********************************************************************\r\n\x1b[0;31mlocalhost\x1b[0m : ok=0 changed=0 unreachable=0 \x1b[0;31mfailed=1 \x1b[0m skipped=0 rescued=0 ignored=0 \r\n\n"))
})

It("determines stdout from an incomplete run", func() {
events := loadFile("./test-events3.jsonl")
stdout := GetStdout(events, nil)
Expect(stdout).To(Equal("\r\nPLAY [ping] ********************************************************************\r\nTASK [ping] ********************************************************************"))
Expect(stdout).To(Equal("\r\nPLAY [ping] ********************************************************************\n\r\nTASK [ping] ********************************************************************\n"))
})

It("determines stdout from an incomplete run (2)", func() {
Expand Down

0 comments on commit ef900cc

Please sign in to comment.