Skip to content

Commit

Permalink
Merge pull request #109 from apenella/change-stdout-in-json-result-fr…
Browse files Browse the repository at this point in the history
…om-string-to-interface{}

Change AnsiblePlaybookJSONResultsPlayTaskHostsItem's Stderr and Stdout attributs from string to interface{}
  • Loading branch information
apenella authored Aug 19, 2022
2 parents 635fbdf + aa11a2e commit eac3b9a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
go-version: 1.15

- name: Test
run: go test -v ./pkg/... -cover -count=1
run: go test ./pkg/... -cover -count=1

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.1.7

### Changed
- On `AnsiblePlaybookJSONResultsPlayTaskHostsItem`, attributes `Stdout` and `Stderr` has been changed from `string` to `interface{}` #109

### Fixed
- On `AnsiblePlaybookJSONResultsPlayTaskHostsItem`, fix `Unreachable` attribute type to `bool` #103

## v1.1.6

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ It supports the most of its options for each command.

To install the latest stable version run the command below:
```
$ go get github.com/apenella/[email protected].6
$ go get github.com/apenella/[email protected].7
```

### Upgrade to 1.x
Expand Down
7 changes: 5 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## undefined
## 1.1.7

### Changed
- On `AnsiblePlaybookJSONResultsPlayTaskHostsItem`, attributes `Stdout` and `Stderr` has been changed from `string` to `interface{}` #109

### Fixed
- On `AnsiblePlaybookJSONResultsPlayTaskHostsItem`, fix `Unreachable` attribute type to bool #103
- On `AnsiblePlaybookJSONResultsPlayTaskHostsItem`, fix `Unreachable` attribute type to `bool` #103
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func main() {

for _, play := range res.Plays {
for _, task := range play.Tasks {
if task.Task.Name == "walk-through-json-output-ansibleplaybook" {
if task.Task.Name == "ansibleplaybook-walk-through-json-output" {
for _, content := range task.Hosts {

err = json.Unmarshal([]byte(content.Stdout), &msgOutput)
err = json.Unmarshal([]byte(fmt.Sprint(content.Stdout)), &msgOutput)
if err != nil {
panic(err)
}
Expand Down
23 changes: 13 additions & 10 deletions pkg/stdoutcallback/results/JSONResults.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ type AnsiblePlaybookJSONResultsPlaysPlay struct {
Duration *AnsiblePlaybookJSONResultsPlayDuration `json:"duration"`
}

/* AnsiblePlaybookJSONResultsPlayTask
'task': {
'name': task.get_name(),
'id': to_text(task._uuid),
'duration': {
'start': current_time()
}
},
/*
AnsiblePlaybookJSONResultsPlayTask
'task': {
'name': task.get_name(),
'id': to_text(task._uuid),
'duration': {
'start': current_time()
}
},
'hosts': {}
*/
type AnsiblePlaybookJSONResultsPlayTask struct {
Expand All @@ -92,9 +95,9 @@ type AnsiblePlaybookJSONResultsPlayTaskHostsItem struct {
Changed bool `json:"changed"`
Msg interface{} `json:"msg"`
AnsibleFacts map[string]interface{} `json:"ansible_facts"`
Stdout string `json:"stdout"`
Stdout interface{} `json:"stdout"`
StdoutLines []string `json:"stdout_lines"`
Stderr string `json:"stderr"`
Stderr interface{} `json:"stderr"`
StderrLines []string `json:"stderr_lines"`
Cmd interface{} `json:"cmd"`
Failed bool `json:"failed"`
Expand Down
17 changes: 14 additions & 3 deletions pkg/stdoutcallback/results/JSONResults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ func TestStdoutCallbackJSONResults(t *testing.T) {

for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {

t.Log(test.desc)

wbuff := bytes.Buffer{}
writer := io.Writer(&wbuff)
reader := bufio.NewReader(strings.NewReader(test.inputResult))
Expand All @@ -370,9 +373,6 @@ func TestStdoutCallbackJSONResults(t *testing.T) {
return
}

fmt.Println(">>>>")
fmt.Println(wbuff.String())
fmt.Println(">>>>")
assert.Equal(t, expectedResult, actualResult, "Unexpected value")
}
})
Expand Down Expand Up @@ -490,6 +490,8 @@ func TestJSONParser(t *testing.T) {

for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
t.Log(test.desc)

res, _ := JSONParse([]byte(test.inputResult))
assert.Equal(t, test.res, res, "Unexpected result")
})
Expand Down Expand Up @@ -1071,6 +1073,7 @@ func TestParseJSONResultsStream(t *testing.T) {
Changed: true,
Stdout: "",
StdoutLines: []string{},
Stderr: "",
StderrLines: []string{},
Cmd: "/usr/bin/true",
Failed: false,
Expand Down Expand Up @@ -1116,6 +1119,7 @@ func TestParseJSONResultsStream(t *testing.T) {
Action: "command",
Changed: true,
Msg: "non-zero return code",
Stdout: "",
StdoutLines: []string{},
Stderr: "",
StderrLines: []string{},
Expand All @@ -1142,6 +1146,7 @@ func TestParseJSONResultsStream(t *testing.T) {
Action: "ansible.builtin.command",
Changed: true,
Msg: "non-zero return code",
Stdout: "",
StdoutLines: []string{},
Stderr: "/usr/bin/ls: cannot access '/tmp/foobar.baz': No such file or directory",
StderrLines: []string{"/usr/bin/ls: cannot access '/tmp/foobar.baz': No such file or directory"},
Expand Down Expand Up @@ -1173,6 +1178,8 @@ func TestParseJSONResultsStream(t *testing.T) {

for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
t.Log(test.desc)

res, err := ParseJSONResultsStream(strings.NewReader(test.inputResult))
if err != nil {
t.Fatalf("unexpected error: %s", err)
Expand Down Expand Up @@ -1217,6 +1224,8 @@ Host: 127.0.0.1

for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
t.Log(test.desc)

res := test.results.String()
assert.Equal(t, test.res, res, "Unexpected result")
})
Expand Down Expand Up @@ -1246,6 +1255,8 @@ func TestAnsiblePlaybookJSONResultsStatsString(t *testing.T) {

for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
t.Log(test.desc)

res := test.stats.String()
assert.Equal(t, test.res, res, "Unexpected result")
})
Expand Down

0 comments on commit eac3b9a

Please sign in to comment.