<commit_before>package test

import (
	"testing"

	"github.com/b2aio/typhon/server"
	"github.com/golang/protobuf/proto"
	"github.com/streadway/amqp"
	"github.com/stretchr/testify/require"
)

var stubServer *StubServer

func InitStubServer(t *testing.T) *StubServer {
	if stubServer == nil {
		stubServer = NewStubServer(t)
	}
	return stubServer
}

// Helper method to call a handler function (the function being tested)
// directly with a `proto.Message`.
// Returns errors that were returned from the handler function directly.
// Marshalling errors cause the test to fail instantly
func CallEndpoint(t *testing.T, endpoint *server.Endpoint, reqProto proto.Message, respProto proto.Message) error {
	// Call handler with amqp delivery
	reqBytes, err := proto.Marshal(reqProto)
	require.NoError(t, err)
	resp, err := endpoint.HandleRequest(server.NewAMQPRequest(&amqp.Delivery{
		Body: reqBytes,
	}))
	if err != nil {
		return err
	}
	respBytes, err := proto.Marshal(resp)
	require.NoError(t, err)
	err = proto.Unmarshal(respBytes, respProto)
	require.NoError(t, err)
	return nil
}
<commit_msg>Add time to test helper delivery params<commit_after>package test

import (
	"testing"
	"time"

	"github.com/b2aio/typhon/server"
	"github.com/golang/protobuf/proto"
	"github.com/streadway/amqp"
	"github.com/stretchr/testify/require"
)

var stubServer *StubServer

func InitStubServer(t *testing.T) *StubServer {
	if stubServer == nil {
		stubServer = NewStubServer(t)
	}
	return stubServer
}

// Helper method to call a handler function (the function being tested)
// directly with a `proto.Message`.
// Returns errors that were returned from the handler function directly.
// Marshalling errors cause the test to fail instantly
func CallEndpoint(t *testing.T, endpoint *server.Endpoint, reqProto proto.Message, respProto proto.Message) error {
	// Call handler with amqp delivery
	reqBytes, err := proto.Marshal(reqProto)
	require.NoError(t, err)
	resp, err := endpoint.HandleRequest(server.NewAMQPRequest(&amqp.Delivery{
		// todo - add other params here
		Timestamp: time.Now().UTC(),
		Body:      reqBytes,
	}))
	if err != nil {
		return err
	}
	respBytes, err := proto.Marshal(resp)
	require.NoError(t, err)
	err = proto.Unmarshal(respBytes, respProto)
	require.NoError(t, err)
	return nil
}

{'fraction_non_alphanumeric': 0.11300174520069808, 'fraction_numerical': 0.0008726003490401396, 'mean_word_length': 4.485645933014354, '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': '4284972', 'n_tokens_mistral': 760, 'n_tokens_neox': 751, 'n_words': 208}