<commit_before>// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package serialization

import (
	"testing"

	"go.opentelemetry.io/collector/consumer/pdata"
)

func TestSerializeIntDataPoints(t *testing.T) {
	type args struct {
		name string
		data pdata.IntDataPointSlice
		tags []string
	}

	intSlice := pdata.NewIntDataPointSlice()
	intSlice.Resize(1)
	intPoint := intSlice.At(0)
	intPoint.SetValue(13)
	intPoint.SetTimestamp(pdata.Timestamp(100_000_000))

	labelIntSlice := pdata.NewIntDataPointSlice()
	labelIntSlice.Resize(1)
	labelIntPoint := labelIntSlice.At(0)
	labelIntPoint.SetValue(13)
	labelIntPoint.SetTimestamp(pdata.Timestamp(100_000_000))
	labelIntPoint.LabelsMap().Insert("labelKey", "labelValue")

	tests := []struct {
		name string
		args args
		want string
	}{
		{
			name: "Serialize integer data points",
			args: args{
				name: "my_int_gauge",
				data: intSlice,
				tags: []string{},
			},
			want: "my_int_gauge 13 100",
		},
		{
			name: "Serialize integer data points with tags",
			args: args{
				name: "my_int_gauge_with_tags",
				data: intSlice,
				tags: []string{"test_key=testval"},
			},
			want: "my_int_gauge_with_tags,test_key=testval 13 100",
		},
		{
			name: "Serialize integer data points with labels",
			args: args{
				name: "my_int_gauge_with_labels",
				data: labelIntSlice,
				tags: []string{},
			},
			want: "my_int_gauge_with_labels,labelkey=\"labelValue\" 13 100",
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := SerializeIntDataPoints(tt.args.name, tt.args.data, tt.args.tags); got != tt.want {
				t.Errorf("SerializeIntDataPoints() = %#v, want %#v", got, tt.want)
			}
		})
	}
}

func TestSerializeDoubleDataPoints(t *testing.T) {
	doubleSlice := pdata.NewDoubleDataPointSlice()
	doubleSlice.Resize(1)
	doublePoint := doubleSlice.At(0)
	doublePoint.SetValue(13.1)
	doublePoint.SetTimestamp(pdata.Timestamp(100_000_000))<commit_msg>Add test for empty dimension (#2473)<commit_after>// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package serialization

import (
	"testing"

	"go.opentelemetry.io/collector/consumer/pdata"
)

func TestSerializeIntDataPoints(t *testing.T) {
	type args struct {
		name string
		data pdata.IntDataPointSlice
		tags []string
	}

	intSlice := pdata.NewIntDataPointSlice()
	intSlice.Resize(1)
	intPoint := intSlice.At(0)
	intPoint.SetValue(13)
	intPoint.SetTimestamp(pdata.Timestamp(100_000_000))

	labelIntSlice := pdata.NewIntDataPointSlice()
	labelIntSlice.Resize(1)
	labelIntPoint := labelIntSlice.At(0)
	labelIntPoint.SetValue(13)
	labelIntPoint.SetTimestamp(pdata.Timestamp(100_000_000))
	labelIntPoint.LabelsMap().Insert("labelKey", "labelValue")

	emptyLabelIntSlice := pdata.NewIntDataPointSlice()
	emptyLabelIntSlice.Resize(1)
	emptyLabelIntPoint := emptyLabelIntSlice.At(0)
	emptyLabelIntPoint.SetValue(13)
	emptyLabelIntPoint.SetTimestamp(pdata.Timestamp(100_000_000))
	emptyLabelIntPoint.LabelsMap().Insert("emptyLabelKey", "")

	tests := []struct {
		name string
		args args
		want string
	}{
		{
			name: "Serialize integer data points",
			args: args{
				name: "my_int_gauge",
				data: intSlice,
				tags: []string{},
			},
			want: "my_int_gauge 13 100",
		},
		{
			name: "Serialize integer data points with tags",
			args: args{
				name: "my_int_gauge_with_tags",
				data: intSlice,
				tags: []string{"test_key=testval"},
			},
			want: "my_int_gauge_with_tags,test_key=testval 13 100",
		},
		{
			name: "Serialize integer data points with labels",
			args: args{
				name: "my_int_gauge_with_labels",
				data: labelIntSlice,
				tags: []string{},
			},
			want: "my_int_gauge_with_labels,labelkey=\"labelValue\" 13 100",
		},
		{
			name: "Serialize integer data points with empty label",
			args: args{
				name: "my_int_gauge_with_empty_labels",
				data: emptyLabelIntSlice,
				tags: []string{},
			},
			want: "my_int_gauge_with_empty_labels,emptylabelkey=\"\" 13 100",
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := SerializeIntDataPoints(tt.args.name, tt.args.data, tt.args.tags); got != tt.want {
				t.Errorf("SerializeIntDataPoints() = %#v, want %#v", got, tt.want)
			}
		})
	}
}

func TestSerializeDoubleDataPoints(t *testing.T) {
	doubleSlice := pdata.NewDoubleDataPointSlice()
	doubleSlice.Resize(1)
	doublePoint := doubleSlice.At(0)
	doublePoint.SetValue(13.1)
	doublePoint.SetTimestamp(pdata.Timestamp(100_000_000))
{'fraction_non_alphanumeric': 0.12404925751539297, 'fraction_numerical': 0.025353132922854037, 'mean_word_length': 4.235071090047393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1692403', 'n_tokens_mistral': 2090, 'n_tokens_neox': 1841, 'n_words': 450}