<commit_before>package core

import (
	"github.com/cep21/gohelpers/a"
	"github.com/signalfuse/com_signalfuse_metrics_protobuf"
	"github.com/signalfuse/signalfxproxy/core/value"
	"testing"
	"time"
)

func TestRelativeDatapoint(t *testing.T) {
	dp := NewRelativeTimeDatapoint("metric", map[string]string{"host": "bob"},
		value.NewIntWire(1), com_signalfuse_metrics_protobuf.MetricType_CUMULATIVE_COUNTER, 0)
	a.ExpectEquals(t, "metric", dp.Metric(), "Unexpected metric")
	a.ExpectEquals(t, "bob", dp.Dimensions()["host"], "Unexpected dimensions")
	iv, err := dp.Value().IntValue()
	a.ExpectEquals(t, int64(1), iv, "Unexpected value")
	a.ExpectEquals(t, nil, err, "Unexpected value")
	a.ExpectEquals(t, com_signalfuse_metrics_protobuf.MetricType_CUMULATIVE_COUNTER, dp.MetricType(), "Unexpected type")
	a.ExpectEquals(t, com_signalfuse_metrics_protobuf.MetricType_CUMULATIVE_COUNTER, dp.MetricType(), "Unexpected time")

	now := time.Now()
	time__Now = func() time.Time { return now }

	a.ExpectEquals(t, now, dp.Timestamp(), "Expected now")

	dp = NewRelativeTimeDatapoint("metric", map[string]string{"host": "bob"},
		value.NewIntWire(1), com_signalfuse_metrics_protobuf.MetricType_CUMULATIVE_COUNTER, -1)
	a.ExpectEquals(t, now.Add(-time.Millisecond), dp.Timestamp(), "Expected now one ms before")
	dp = NewRelativeTimeDatapoint("metric", map[string]string{"host": "bob"},
		value.NewIntWire(1), com_signalfuse_metrics_protobuf.MetricType_CUMULATIVE_COUNTER, now.UnixNano()/int64(time.Millisecond))
	a.ExpectContains(t, dp.String(), "bob", "Got string for dp")
	a.ExpectEquals(t, now.Round(time.Second), dp.Timestamp().Round(time.Second), "Expected exact unix time")
}

func TestAbsoluteDatapoint(t *testing.T) {
	curTime := time.Now()<commit_msg>Fix tests<commit_after>package core

import (
	"github.com/cep21/gohelpers/a"
	"github.com/signalfuse/com_signalfuse_metrics_protobuf"
	"github.com/signalfuse/signalfxproxy/core/value"
	"testing"
	"time"
)

func TestRelativeDatapoint(t *testing.T) {
	dp := NewRelativeTimeDatapoint("metric", map[string]string{"host": "bob"},
		value.NewIntWire(1), com_signalfuse_metrics_protobuf.MetricType_CUMULATIVE_COUNTER, 0)
	a.ExpectEquals(t, "metric", dp.Metric(), "Unexpected metric")
	a.ExpectEquals(t, "bob", dp.Dimensions()["host"], "Unexpected dimensions")
	iv, err := dp.Value().IntValue()
	a.ExpectEquals(t, int64(1), iv, "Unexpected value")
	a.ExpectEquals(t, nil, err, "Unexpected value")
	a.ExpectEquals(t, com_signalfuse_metrics_protobuf.MetricType_CUMULATIVE_COUNTER, dp.MetricType(), "Unexpected type")
	a.ExpectEquals(t, com_signalfuse_metrics_protobuf.MetricType_CUMULATIVE_COUNTER, dp.MetricType(), "Unexpected time")

	now := time.Now()
	timeXXXXNow = func() time.Time { return now }

	a.ExpectEquals(t, now, dp.Timestamp(), "Expected now")

	dp = NewRelativeTimeDatapoint("metric", map[string]string{"host": "bob"},
		value.NewIntWire(1), com_signalfuse_metrics_protobuf.MetricType_CUMULATIVE_COUNTER, -1)
	a.ExpectEquals(t, now.Add(-time.Millisecond), dp.Timestamp(), "Expected now one ms before")
	dp = NewRelativeTimeDatapoint("metric", map[string]string{"host": "bob"},
		value.NewIntWire(1), com_signalfuse_metrics_protobuf.MetricType_CUMULATIVE_COUNTER, now.UnixNano()/int64(time.Millisecond))
	a.ExpectContains(t, dp.String(), "bob", "Got string for dp")
	a.ExpectEquals(t, now.Round(time.Second), dp.Timestamp().Round(time.Second), "Expected exact unix time")
}

func TestAbsoluteDatapoint(t *testing.T) {
	curTime := time.Now()
{'fraction_non_alphanumeric': 0.15397824842587293, 'fraction_numerical': 0.006868918145392101, 'mean_word_length': 7.4014423076923075, 'pattern_counts': {'":': 6, '<': 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': '3789946', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1243, 'n_words': 208}