github.com/alibaba/ilogtail/pkg@v0.0.0-20250526110833-c53b480d046c/helper/split_log_helper_test.go (about)

     1  // Copyright 2023 iLogtail Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package helper
    16  
    17  import (
    18  	"strconv"
    19  	"testing"
    20  	"time"
    21  
    22  	"github.com/stretchr/testify/assert"
    23  
    24  	"github.com/alibaba/ilogtail/pkg/protocol"
    25  )
    26  
    27  func TestReviseFileOffset(t *testing.T) {
    28  	var mock protocol.Log
    29  	mock.Contents = append(mock.Contents, &protocol.Log_Content{Key: FileOffsetKey, Value: "1000"})
    30  	mock.Time = uint32(time.Now().Unix())
    31  
    32  	tests := []struct {
    33  		name   string
    34  		log    *protocol.Log
    35  		offset int64
    36  		want   int64
    37  	}{
    38  		{
    39  			name:   "revise_file",
    40  			log:    &mock,
    41  			offset: 101,
    42  			want:   1101,
    43  		},
    44  	}
    45  	for _, tt := range tests {
    46  		t.Run(tt.name, func(t *testing.T) {
    47  			ReviseFileOffset(tt.log, 101, true)
    48  			cont := GetFileOffsetTag(tt.log)
    49  			assert.True(t, cont != nil)
    50  			off, err := strconv.ParseInt(cont.Value, 10, 64)
    51  			assert.True(t, err == nil)
    52  			assert.Equal(t, tt.want, off)
    53  		})
    54  	}
    55  }