-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes issue with JSON renderer (#281)
* Fixes issue with JSON renderer * Adds test cases
- Loading branch information
Showing
10 changed files
with
123 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
// Package json contains functionality to render output in json format | ||
package json | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/devops-kung-fu/bomber/lib" | ||
"github.com/devops-kung-fu/bomber/models" | ||
"github.com/devops-kung-fu/common/util" | ||
) | ||
|
||
// Renderer contains methods to render to JSON format | ||
type Renderer struct{} | ||
|
||
// Render outputs json to STDOUT | ||
func (Renderer) Render(results models.Results) error { | ||
b, _ := json.MarshalIndent(results, "", "\t") | ||
filename := lib.GenerateFilename("json") | ||
util.PrintInfo("Writing JSON output:", filename) | ||
if err := os.WriteFile(filename, b, 0666); err != nil { | ||
log.Fatal(err) | ||
b, err := json.MarshalIndent(results, "", "\t") | ||
if err != nil { | ||
log.Println(err) | ||
return err | ||
} | ||
|
||
fmt.Println(string(b)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Package json contains functionality to render output in json format | ||
package jsonfile | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"os" | ||
|
||
"github.com/devops-kung-fu/common/util" | ||
|
||
"github.com/devops-kung-fu/bomber/lib" | ||
"github.com/devops-kung-fu/bomber/models" | ||
) | ||
|
||
// Renderer contains methods to render to JSON format | ||
type Renderer struct{} | ||
|
||
// Render outputs json to STDOUT | ||
func (Renderer) Render(results models.Results) error { | ||
b, _ := json.MarshalIndent(results, "", "\t") | ||
filename := lib.GenerateFilename("json") | ||
util.PrintInfo("Writing JSON output:", filename) | ||
if err := os.WriteFile(filename, b, 0666); err != nil { | ||
log.Fatal(err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters