github.com/kubeshop/testkube@v1.17.23/pkg/logs/events/events_test.go (about)

     1  package events
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestNewLogFromBytes(t *testing.T) {
    10  	assert := require.New(t)
    11  
    12  	t.Run("log line with timestamp passed from kube api", func(t *testing.T) {
    13  		b := []byte("2024-03-11T10:47:41.070097107Z Line")
    14  
    15  		l := NewLogFromBytes(b)
    16  
    17  		assert.Equal("2024-03-11 10:47:41.070097107 +0000 UTC", l.Time.String())
    18  		assert.Equal("Line", l.Content)
    19  	})
    20  
    21  	t.Run("log line without timestamp", func(t *testing.T) {
    22  		b := []byte("Line")
    23  
    24  		l := NewLogFromBytes(b)
    25  
    26  		assert.Equal("Line", l.Content)
    27  	})
    28  
    29  	t.Run("old log line without timestamp", func(t *testing.T) {
    30  		b := []byte(`{"content":"Line"}`)
    31  
    32  		l := NewLogFromBytes(b)
    33  
    34  		assert.Equal("Line", l.Content)
    35  	})
    36  
    37  }