Skip to content

Commit

Permalink
Add back the Marshal and fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsbhat committed Jan 27, 2024
1 parent d40eeaa commit 85c315a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
9 changes: 9 additions & 0 deletions content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ func (obj Object) CheckFileType(log *logrus.Logger) string {
return FileTypeUnknown
}

func Marshal(data interface{}) (Object, error) {
out, err := json.Marshal(data)
if err != nil {
return "", err
}

return Object(out), nil
}

// String should return the string equivalent of Object.
func (obj Object) String() string {
return string(obj)
Expand Down
2 changes: 1 addition & 1 deletion content/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ name: "testing"`)

strReader := new(bytes.Buffer)

render := renderer.GetRenderer(strReader, log, false, false, false, true)
render := renderer.GetRenderer(strReader, log, false, false, false, false, true)

err := render.Render(data)
assert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions renderer/color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Test_colorJSON(t *testing.T) {
cliShellReadConfig := prompt.NewReadConfig("gocd-cli", "this is test message", inputOptions, logrus.New())

strReader := new(bytes.Buffer)
config := renderer.GetRenderer(strReader, logrus.New(), false, true, false, false)
config := renderer.GetRenderer(strReader, logrus.New(), false, false, true, false, false)

colorString, err := config.ColorJSON(cliShellReadConfig)
assert.NoError(t, err)
Expand All @@ -33,7 +33,7 @@ func Test_colorJSON(t *testing.T) {
assert.NoError(t, err)

strReader := new(bytes.Buffer)
config := renderer.GetRenderer(strReader, logrus.New(), true, false, false, false)
config := renderer.GetRenderer(strReader, logrus.New(), false, true, false, false, false)

colorString, err := config.ColorYAML(string(valueYAML))
assert.NoError(t, err)
Expand Down
14 changes: 7 additions & 7 deletions renderer/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestGetRenderer(t *testing.T) {
strReader := new(bytes.Buffer)

logger := logrus.New()
render := renderer.GetRenderer(strReader, logger, false, false, true, false)
render := renderer.GetRenderer(strReader, logger, false, false, false, true, false)

inputOptions := []prompt.Options{{Name: "yes", Short: "y"}, {Name: "no", Short: "n"}}
cliShellReadConfig := prompt.NewReadConfig("gocd-cli", "this is test message", inputOptions, logger)
Expand All @@ -35,7 +35,7 @@ func TestGetRenderer(t *testing.T) {
strReader := new(bytes.Buffer)

logger := logrus.New()
render := renderer.GetRenderer(strReader, logger, false, true, false, false)
render := renderer.GetRenderer(strReader, logger, false, false, true, false, false)

inputOptions := []prompt.Options{{Name: "yes", Short: "y"}, {Name: "no", Short: "n"}}
cliShellReadConfig := prompt.NewReadConfig("gocd-cli", "this is test message", inputOptions, logger)
Expand All @@ -52,7 +52,7 @@ func TestGetRenderer(t *testing.T) {
strReader := new(bytes.Buffer)

logger := logrus.New()
render := renderer.GetRenderer(strReader, logger, true, false, false, false)
render := renderer.GetRenderer(strReader, logger, false, true, false, false, false)

inputOptions := []prompt.Options{{Name: "yes", Short: "y"}, {Name: "no", Short: "n"}}
cliShellReadConfig := prompt.NewReadConfig("gocd-cli", "this is test message", inputOptions, logger)
Expand All @@ -70,7 +70,7 @@ func TestGetRenderer(t *testing.T) {

logger := logrus.New()
logger.SetLevel(logrus.DebugLevel)
render := renderer.GetRenderer(strReader, logger, false, false, false, true)
render := renderer.GetRenderer(strReader, logger, false, false, false, false, true)

data := [][]string{
{"sn", "cat", "value"},
Expand All @@ -92,7 +92,7 @@ func TestGetRenderer(t *testing.T) {
strReader := new(bytes.Buffer)

logger := logrus.New()
render := renderer.GetRenderer(strReader, logger, false, false, false, false)
render := renderer.GetRenderer(strReader, logger, false, false, false, false, false)

inputOptions := []prompt.Options{{Name: "yes", Short: "y"}, {Name: "no", Short: "n"}}
cliShellReadConfig := prompt.NewReadConfig("gocd-cli", "this is test message", inputOptions, logger)
Expand All @@ -103,7 +103,7 @@ func TestGetRenderer(t *testing.T) {

t.Run("should render in defaults to stdout since no writer or render type specified", func(t *testing.T) {
logger := logrus.New()
render := renderer.GetRenderer(nil, logger, false, false, false, false)
render := renderer.GetRenderer(nil, logger, false, false, false, false, false)

inputOptions := []prompt.Options{{Name: "yes", Short: "y"}, {Name: "no", Short: "n"}}
cliShellReadConfig := prompt.NewReadConfig("gocd-cli", "this is test message", inputOptions, logger)
Expand All @@ -124,7 +124,7 @@ func TestGetRenderer(t *testing.T) {
}

logger := logrus.New()
render := renderer.GetRenderer(os.Stdout, logger, true, false, false, false)
render := renderer.GetRenderer(os.Stdout, logger, false, true, false, false, false)

if err := render.Render(newObject); err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 85c315a

Please sign in to comment.