github.com/yaoapp/kun@v0.9.0/utils/utils_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/yaoapp/kun/maps"
    11  )
    12  
    13  func TestDump(t *testing.T) {
    14  	rescueStdout := os.Stdout
    15  	r, w, _ := os.Pipe()
    16  	os.Stdout = w
    17  	Dump(maps.Str{
    18  		"foo": "bar",
    19  		"nested": maps.Str{
    20  			"foo": "bar",
    21  		},
    22  	})
    23  	w.Close()
    24  	out, _ := ioutil.ReadAll(r)
    25  	os.Stdout = rescueStdout
    26  	assert.True(t, strings.Contains(string(out), "foo"), "the command return value should be have foo...")
    27  }