github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/countlog/output/json/json_test.go (about)

     1  package json
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  	"github.com/v2pro/plz/countlog/spi"
     8  )
     9  
    10  func Test_event(t *testing.T) {
    11  	should := require.New(t)
    12  	format := &JsonFormat{}
    13  	formatter := format.FormatterOf(&spi.LogSite{
    14  		Sample: []interface{}{
    15  			"k1", "v",
    16  			"k2", 100,
    17  		},
    18  	})
    19  	output := formatter.Format(nil, &spi.Event{
    20  		Properties: []interface{}{
    21  			"k1", "v",
    22  			"k2", 100,
    23  		},
    24  	})
    25  	should.Equal(`{"k1":"v","k2":100}`, string(output))
    26  }