github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/logging/loggers/sort_logger_test.go (about)

     1  package loggers
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func Test_sortKeyvals(t *testing.T) {
    11  	keyvals := []interface{}{"foo", 3, "bar", 5}
    12  	indices := map[string]int{"foo": 1, "bar": 0}
    13  	sortKeyvals(indices, keyvals)
    14  	assert.Equal(t, []interface{}{"bar", 5, "foo", 3}, keyvals)
    15  }
    16  
    17  func TestSortLogger(t *testing.T) {
    18  	testLogger := newTestLogger()
    19  	sortLogger := SortLogger(testLogger, "foo", "bar", "baz")
    20  	sortLogger.Log([][]int{}, "bar", "foo", 3, "baz", "horse", "crabs", "cycle", "bar", 4, "ALL ALONE")
    21  	sortLogger.Log("foo", 0)
    22  	sortLogger.Log("bar", "foo", "foo", "baz")
    23  	lines, err := testLogger.logLines(3)
    24  	require.NoError(t, err)
    25  	// non string keys sort after string keys, specified keys sort before unspecifed keys, specified key sort in order
    26  	assert.Equal(t, [][]interface{}{
    27  		{"foo", 3, "bar", 4, "baz", "horse", [][]int{}, "bar", "crabs", "cycle", "ALL ALONE"},
    28  		{"foo", 0},
    29  		{"foo", "baz", "bar", "foo"},
    30  	}, lines)
    31  }