<commit_before>package veneur

import (
	"testing"

	"github.com/gogo/protobuf/proto"
	"github.com/stretchr/testify/assert"
	"github.com/stripe/veneur/samplers"
	"github.com/stripe/veneur/ssf"
)

func freshSSFMetric() *ssf.SSFSample {
	return &ssf.SSFSample{
		Metric:     0,
		Name:       "test.ssf_metric",
		Value:      5,
		Message:    "test_msg",
		Status:     0,
		SampleRate: 1,
		Tags: map[string]string{
			"tag1": "value1",
			"tag2": "value2",
		},
	}
}

func TestValidMetric(t *testing.T) {
	metric := freshSSFMetric()

	m, _ := samplers.ParseMetricSSF(metric)
	assert.True(t, samplers.ValidMetric(m))

	metric.Name = ""
	m, _ = samplers.ParseMetricSSF(metric)
	assert.False(t, samplers.ValidMetric(m))

	metric.SampleRate = 0
	m, _ = samplers.ParseMetricSSF(metric)
	assert.False(t, samplers.ValidMetric(m))
	assert.Equal(t, float32(1), m.SampleRate)
}

func TestValidTrace(t *testing.T) {
	trace := &ssf.SSFSpan{}
	assert.False(t, samplers.ValidTrace(trace))
	assert.NotNil(t, trace.Tags)

	trace.Id = 1
	trace.TraceId = 1
	trace.StartTimestamp = 1
	trace.EndTimestamp = 5
	assert.True(t, samplers.ValidTrace(trace))
}

func TestParseSSFUnmarshal(t *testing.T) {
	test := []byte{'0'}
	sample, metrics, err := samplers.ParseSSF(test)

	assert.Nil(t, sample)
	assert.Zero(t, len(metrics))
	assert.NotNil(t, err)
	assert.Equal(t, "unmarshal", err.Error())
}

func TestParseSSFEmpty(t *testing.T) {
	trace := &ssf.SSFSpan{}

	buff, err := proto.Marshal(trace)
	assert.Nil(t, err)

	sample, metrics, err := samplers.ParseSSF(buff)
	assert.Nil(t, sample)
	assert.Nil(t, metrics)
	assert.Nil(t, err)
}<commit_msg>Fix test failure<commit_after>package veneur

import (
	"testing"

	"github.com/gogo/protobuf/proto"
	"github.com/stretchr/testify/assert"
	"github.com/stripe/veneur/samplers"
	"github.com/stripe/veneur/ssf"
)

func freshSSFMetric() *ssf.SSFSample {
	return &ssf.SSFSample{
		Metric:     0,
		Name:       "test.ssf_metric",
		Value:      5,
		Message:    "test_msg",
		Status:     0,
		SampleRate: 1,
		Tags: map[string]string{
			"tag1": "value1",
			"tag2": "value2",
		},
	}
}

func TestValidMetric(t *testing.T) {
	metric := freshSSFMetric()

	m, _ := samplers.ParseMetricSSF(metric)
	assert.True(t, samplers.ValidMetric(m))

	metric.Name = ""
	m, _ = samplers.ParseMetricSSF(metric)
	assert.False(t, samplers.ValidMetric(m))

	metric.SampleRate = 0
	m, _ = samplers.ParseMetricSSF(metric)
	assert.False(t, samplers.ValidMetric(m))
	assert.Equal(t, float32(1), m.SampleRate)
}

func TestValidTrace(t *testing.T) {
	trace := &ssf.SSFSpan{}
	assert.False(t, samplers.ValidTrace(trace))
	assert.NotNil(t, trace.Tags)

	trace.Id = 1
	trace.TraceId = 1
	trace.StartTimestamp = 1
	trace.EndTimestamp = 5
	assert.True(t, samplers.ValidTrace(trace))
}

func TestParseSSFUnmarshal(t *testing.T) {
	test := []byte{'0'}
	sample, metrics, err := samplers.ParseSSF(test)

	assert.Nil(t, sample)
	assert.Zero(t, len(metrics))
	assert.NotNil(t, err)
	assert.Equal(t, "unmarshal", err.Error())
}

func TestParseSSFEmpty(t *testing.T) {
	trace := &ssf.SSFSpan{}

	buff, err := proto.Marshal(trace)
	assert.Nil(t, err)

	sample, metrics, err := samplers.ParseSSF(buff)
	assert.Nil(t, sample)
	assert.Zero(t, len(metrics))
	assert.Nil(t, err)
}
{'fraction_non_alphanumeric': 0.16189596799015082, 'fraction_numerical': 0.010464758387196061, 'mean_word_length': 4.389718076285241, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2523854', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1327, 'n_words': 224}