github.com/alibaba/ilogtail/pkg@v0.0.0-20250526110833-c53b480d046c/protocol/converter/converter_test.go (about)

     1  // Copyright 2022 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 protocol
    16  
    17  import (
    18  	"testing"
    19  
    20  	. "github.com/smartystreets/goconvey/convey"
    21  
    22  	"github.com/alibaba/ilogtail/pkg/config"
    23  	"github.com/alibaba/ilogtail/pkg/protocol"
    24  )
    25  
    26  func TestInvalidProtocol(t *testing.T) {
    27  	Convey("When constructing converter with invalid protocol", t, func() {
    28  		_, err := NewConverter("xml", "pb", nil, nil, &config.GlobalConfig{})
    29  
    30  		Convey("Then error should be returned", func() {
    31  			So(err, ShouldNotBeNil)
    32  		})
    33  	})
    34  
    35  	Convey("Given a converter with unsupported protocol", t, func() {
    36  		c := &Converter{
    37  			Protocol: "xml",
    38  			Encoding: "pb",
    39  		}
    40  
    41  		Convey("When performing conversion", func() {
    42  			logs := []*protocol.Log{
    43  				{
    44  					Time: 1662434209,
    45  					Contents: []*protocol.Log_Content{
    46  						{Key: "method", Value: "PUT"},
    47  					},
    48  				},
    49  			}
    50  			tags := []*protocol.LogTag{
    51  				{Key: "__hostname__", Value: "alje834hgf"},
    52  				{Key: "__pack_id__", Value: "AEDCFGHNJUIOPLMN-1E"},
    53  				{Key: "__path__", Value: "/root/test/origin/example.log"},
    54  				{Key: "__log_topic__", Value: "file"},
    55  			}
    56  			logGroup := &protocol.LogGroup{
    57  				Logs:     logs,
    58  				Category: "test",
    59  				Topic:    "topic",
    60  				Source:   "172.10.0.56",
    61  				LogTags:  tags,
    62  			}
    63  
    64  			_, err := c.Do(logGroup)
    65  
    66  			Convey("Then error should be returned", func() {
    67  				So(err, ShouldNotBeNil)
    68  			})
    69  		})
    70  	})
    71  }