110 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Go
		
	
	
	
			
		
		
	
	
			110 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Go
		
	
	
	
// Copyright The OpenTelemetry Authors
 | 
						|
// SPDX-License-Identifier: Apache-2.0
 | 
						|
 | 
						|
// Code generated by "internal/cmd/pdatagen/main.go". DO NOT EDIT.
 | 
						|
// To regenerate this file run "make genpdata".
 | 
						|
 | 
						|
package internal
 | 
						|
 | 
						|
import (
 | 
						|
	"testing"
 | 
						|
 | 
						|
	"github.com/stretchr/testify/assert"
 | 
						|
	"github.com/stretchr/testify/require"
 | 
						|
	gootlpprofiles "go.opentelemetry.io/proto/slim/otlp/profiles/v1development"
 | 
						|
	"google.golang.org/protobuf/proto"
 | 
						|
 | 
						|
	otlpprofiles "go.opentelemetry.io/collector/pdata/internal/data/protogen/profiles/v1development"
 | 
						|
	"go.opentelemetry.io/collector/pdata/internal/json"
 | 
						|
)
 | 
						|
 | 
						|
func TestCopyOrigFunction(t *testing.T) {
 | 
						|
	src := NewOrigPtrFunction()
 | 
						|
	dest := NewOrigPtrFunction()
 | 
						|
	CopyOrigFunction(dest, src)
 | 
						|
	assert.Equal(t, NewOrigPtrFunction(), dest)
 | 
						|
	FillOrigTestFunction(src)
 | 
						|
	CopyOrigFunction(dest, src)
 | 
						|
	assert.Equal(t, src, dest)
 | 
						|
}
 | 
						|
 | 
						|
func TestMarshalAndUnmarshalJSONOrigFunctionUnknown(t *testing.T) {
 | 
						|
	iter := json.BorrowIterator([]byte(`{"unknown": "string"}`))
 | 
						|
	defer json.ReturnIterator(iter)
 | 
						|
	dest := NewOrigPtrFunction()
 | 
						|
	UnmarshalJSONOrigFunction(dest, iter)
 | 
						|
	require.NoError(t, iter.Error())
 | 
						|
	assert.Equal(t, NewOrigPtrFunction(), dest)
 | 
						|
}
 | 
						|
 | 
						|
func TestMarshalAndUnmarshalJSONOrigFunction(t *testing.T) {
 | 
						|
	for name, src := range getEncodingTestValuesFunction() {
 | 
						|
		t.Run(name, func(t *testing.T) {
 | 
						|
			stream := json.BorrowStream(nil)
 | 
						|
			defer json.ReturnStream(stream)
 | 
						|
			MarshalJSONOrigFunction(src, stream)
 | 
						|
			require.NoError(t, stream.Error())
 | 
						|
 | 
						|
			iter := json.BorrowIterator(stream.Buffer())
 | 
						|
			defer json.ReturnIterator(iter)
 | 
						|
			dest := NewOrigPtrFunction()
 | 
						|
			UnmarshalJSONOrigFunction(dest, iter)
 | 
						|
			require.NoError(t, iter.Error())
 | 
						|
 | 
						|
			assert.Equal(t, src, dest)
 | 
						|
		})
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func TestMarshalAndUnmarshalProtoOrigFunctionUnknown(t *testing.T) {
 | 
						|
	dest := NewOrigPtrFunction()
 | 
						|
	// message Test { required int64 field = 1313; } encoding { "field": "1234" }
 | 
						|
	require.NoError(t, UnmarshalProtoOrigFunction(dest, []byte{0x88, 0x52, 0xD2, 0x09}))
 | 
						|
	assert.Equal(t, NewOrigPtrFunction(), dest)
 | 
						|
}
 | 
						|
 | 
						|
func TestMarshalAndUnmarshalProtoOrigFunction(t *testing.T) {
 | 
						|
	for name, src := range getEncodingTestValuesFunction() {
 | 
						|
		t.Run(name, func(t *testing.T) {
 | 
						|
			buf := make([]byte, SizeProtoOrigFunction(src))
 | 
						|
			gotSize := MarshalProtoOrigFunction(src, buf)
 | 
						|
			assert.Equal(t, len(buf), gotSize)
 | 
						|
 | 
						|
			dest := NewOrigPtrFunction()
 | 
						|
			require.NoError(t, UnmarshalProtoOrigFunction(dest, buf))
 | 
						|
			assert.Equal(t, src, dest)
 | 
						|
		})
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func TestMarshalAndUnmarshalProtoViaProtobufFunction(t *testing.T) {
 | 
						|
	for name, src := range getEncodingTestValuesFunction() {
 | 
						|
		t.Run(name, func(t *testing.T) {
 | 
						|
			buf := make([]byte, SizeProtoOrigFunction(src))
 | 
						|
			gotSize := MarshalProtoOrigFunction(src, buf)
 | 
						|
			assert.Equal(t, len(buf), gotSize)
 | 
						|
 | 
						|
			goDest := &gootlpprofiles.Function{}
 | 
						|
			require.NoError(t, proto.Unmarshal(buf, goDest))
 | 
						|
 | 
						|
			goBuf, err := proto.Marshal(goDest)
 | 
						|
			require.NoError(t, err)
 | 
						|
 | 
						|
			dest := NewOrigPtrFunction()
 | 
						|
			require.NoError(t, UnmarshalProtoOrigFunction(dest, goBuf))
 | 
						|
			assert.Equal(t, src, dest)
 | 
						|
		})
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func getEncodingTestValuesFunction() map[string]*otlpprofiles.Function {
 | 
						|
	return map[string]*otlpprofiles.Function{
 | 
						|
		"empty": NewOrigPtrFunction(),
 | 
						|
		"fill_test": func() *otlpprofiles.Function {
 | 
						|
			src := NewOrigPtrFunction()
 | 
						|
			FillOrigTestFunction(src)
 | 
						|
			return src
 | 
						|
		}(),
 | 
						|
	}
 | 
						|
}
 |