194ed8e2ad
Previously, we would just use normal go formatting when displaying output values. This was fine for simple values like strings and ints, but for arrays or objects, you'd end up with values that looked a little stange. We now run the objects through json.Marshal first, to get nicer string values for more complex objects. However, when the top level value is a single string, we elide the quotes. This is not true JSON, but it displays much nicer. When we add something like `--format=json` (see pulumi#496) it will provide a way to treat output unfiormly as JSON. Fixes #736
24 lines
518 B
Go
24 lines
518 B
Go
package cmd
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestStringifyOutput(t *testing.T) {
|
|
num := 42
|
|
str := "ABC"
|
|
arr := []string{"hello", "goodbye"}
|
|
obj := map[string]interface{}{
|
|
"foo": 42,
|
|
"bar": map[string]interface{}{
|
|
"baz": true,
|
|
},
|
|
}
|
|
|
|
assert.Equal(t, "42", stringifyOutput(num))
|
|
assert.Equal(t, "ABC", stringifyOutput(str))
|
|
assert.Equal(t, "[\"hello\",\"goodbye\"]", stringifyOutput(arr))
|
|
assert.Equal(t, "{\"bar\":{\"baz\":true},\"foo\":42}", stringifyOutput(obj))
|
|
}
|