github.com/smartcontractkit/chainlink-testing-framework/libs@v0.0.0-20240227141906-ec710b4eb1a3/logging/log_test.go (about)

     1  package logging
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestLogAfterTestEnd(t *testing.T) {
    12  	l := GetTestLogger(t)
    13  	go func() {
    14  		for i := 0; i < 5000; i++ {
    15  			l.Info().Msg("test")
    16  		}
    17  	}()
    18  	time.Sleep(1 * time.Millisecond)
    19  }
    20  
    21  func TestGetTestLogger(t *testing.T) {
    22  	l := GetTestLogger(t)
    23  	l.Info().Msg("test")
    24  	require.NotNil(t, l)
    25  }
    26  
    27  func TestGetTestContainersGoTestLogger(t *testing.T) {
    28  	l := GetTestContainersGoTestLogger(t)
    29  	require.NotNil(t, l.(CustomT).L)
    30  }
    31  
    32  // TestSplitStringIntoChunks tests the splitStringIntoChunks function with a string up to a million characters.
    33  func TestSplitStringIntoChunks(t *testing.T) {
    34  	// Create a test string with a million and 1 characters ('a').
    35  	testString := strings.Repeat("a", 1000001)
    36  	chunkSize := 100000
    37  	expectedNumChunks := 11
    38  
    39  	chunks := SplitStringIntoChunks(testString, chunkSize)
    40  
    41  	require.Equal(t, expectedNumChunks, len(chunks), "Wrong number of chunks")
    42  
    43  	// Check the size of each chunk.
    44  	for i, chunk := range chunks {
    45  		require.False(t, i < expectedNumChunks-1 && len(chunk) != chunkSize, "Chunk %d is not of expected size %d", i+1, chunkSize)
    46  
    47  		// Check the last chunk size.
    48  		if i == expectedNumChunks-1 {
    49  			require.Equal(t, 1, len(chunk), "Last chunk is not of expected size")
    50  		}
    51  	}
    52  }