<commit_before>package sfxproto

import (
	"fmt"
	"testing"
	"time"

	"github.com/golang/protobuf/proto"
	. "github.com/smartystreets/goconvey/convey"
)

func TestSignalFXProto(t *testing.T) {
	p := &DataPoint{
		Metric:     proto.String("metric0"),
		MetricType: MetricType_CUMULATIVE_COUNTER.Enum(),
		Value:      &Datum{IntValue: proto.Int64(64)},
		Dimensions: []*Dimension{
			{Key: proto.String("key0"), Value: proto.String("value0")},
		},
	}
	now := time.Now()
	p.SetTime(now)
	now = time.Unix(0, now.UnixNano()/int64(time.Millisecond))

	Convey("Testing SignalFX Proto", t, func() {
		Convey("MetricType", func() {
			mt := MetricType_GAUGE
			So(mt.String(), ShouldEqual, "GAUGE")

			data, err := proto.MarshalJSONEnum(MetricType_name, int32(mt))
			So(err, ShouldBeNil)

			var mt2 MetricType
			err = mt2.UnmarshalJSON(data)
			So(err, ShouldBeNil)
			So(mt, ShouldEqual, mt2)

			err = mt2.UnmarshalJSON([]byte("{}"))
			So(err, ShouldNotBeNil)
			So(err.Error(), ShouldResemble, "cannot unmarshal `{}` into enum MetricType")
		})

		Convey("Datum", func() {
			d := &Datum{
				IntValue: proto.Int64(16),
			}

			So(d.StrValue, ShouldBeNil)
			So(d.DoubleValue, ShouldBeNil)
			So(*d.IntValue, ShouldEqual, 16)

			d.Reset()
			So(d.StrValue, ShouldBeNil)
			So(d.DoubleValue, ShouldBeNil)
			So(d.IntValue, ShouldBeNil)

			d.ProtoMessage() // noop<commit_msg>fix tests<commit_after>package sfxproto

import (
	"fmt"
	"testing"
	"time"

	"github.com/golang/protobuf/proto"
	. "github.com/smartystreets/goconvey/convey"
)

func TestSignalFXProto(t *testing.T) {
	p := &DataPoint{
		Metric:     proto.String("metric0"),
		MetricType: MetricType_CUMULATIVE_COUNTER.Enum(),
		Value:      &Datum{IntValue: proto.Int64(64)},
		Dimensions: []*Dimension{
			{Key: proto.String("key0"), Value: proto.String("value0")},
		},
	}
	now := time.Now()
	p.SetTime(now)
	now = time.Unix(0, now.UnixNano()/int64(time.Millisecond))

	Convey("Testing SignalFX Proto", t, func() {
		Convey("MetricType", func() {
			// TODO(jrubin) this test depended on a feature of gogo protobuf, is
			// it necessary still?

			// mt := MetricType_GAUGE
			// So(mt.String(), ShouldEqual, "GAUGE")
			//
			// data, err := proto.MarshalJSONEnum(MetricType_name, int32(mt))
			// So(err, ShouldBeNil)
			//
			// var mt2 MetricType
			// err = mt2.UnmarshalJSON(data)
			// So(err, ShouldBeNil)
			// So(mt, ShouldEqual, mt2)
			//
			// err = mt2.UnmarshalJSON([]byte("{}"))
			// So(err, ShouldNotBeNil)
			// So(err.Error(), ShouldResemble, "cannot unmarshal `{}` into enum MetricType")
		})

		Convey("Datum", func() {
			d := &Datum{
				IntValue: proto.Int64(16),
			}

			So(d.StrValue, ShouldBeNil)
			So(d.DoubleValue, ShouldBeNil)
			So(*d.IntValue, ShouldEqual, 16)

			d.Reset()
			So(d.StrValue, ShouldBeNil)
			So(d.DoubleValue, ShouldBeNil)
			So(d.IntValue, ShouldBeNil)

			d.ProtoMessage() // noop
{'fraction_non_alphanumeric': 0.16983085950983776, 'fraction_numerical': 0.015188125647221263, 'mean_word_length': 3.7430441898527005, 'pattern_counts': {'":': 0, '<': 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': '3796652', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1120, 'n_words': 202}