<commit_before>package mailcmd

import (
	"github.com/HouzuoGuo/laitos/daemon/common"
	"github.com/HouzuoGuo/laitos/inet"
	"net"
	"strings"
	"testing"
)

func TestMailProcessor_Process(t *testing.T) {
	runner := CommandRunner{
		Processor:         &common.CommandProcessor{},
		CommandTimeoutSec: 5,
		ReplyMailClient: inet.MailClient{
			MTAHost:  "127.0.0.1",
			MTAPort:  25,
			MailFrom: "<EMAIL>",
		},
		Undocumented1: TestUndocumented1,
	}
	if err := runner.Initialise(); err == nil || strings.Index(err.Error(), "filters must be configured") == -1 {
		t.Fatal(err)
	}
	// CommandRunner has insane command processor
	runner.Processor = common.GetInsaneCommandProcessor()
	if err := runner.Initialise(); err == nil || strings.Index(err.Error(), "PIN is too short") == -1 {
		t.Fatal(err)
	}
	// Prepare a good processor
	runner.Processor = common.GetTestCommandProcessor()
	TestCommandRunner(&runner, t)
}

func TestMailProcessor_Process_Undocumented1Reply(t *testing.T) {
	if TestUndocumented1Message == "" {
		t.Skip()
	}
	runner := CommandRunner{
		CommandTimeoutSec: 5,
		ReplyMailClient: inet.MailClient{
			MTAHost:  "127.0.0.1",
			MTAPort:  25,
			MailFrom: "<EMAIL>",
		},
		Undocumented1: TestUndocumented1,
	}
	// Prepare a good processor
	runner.Processor = common.GetTestCommandProcessor()
	runner.Processor.Features.WolframAlpha = TestWolframAlpha
	runner.Processor.Features.LookupByTrigger[TestWolframAlpha.Trigger()] = &TestWolframAlpha
	if err := runner.Process([]byte(TestUndocumented1Message)); err != nil {
		t.Fatal(err)
	}
	// Real MTA is required for the self test
	if _, err := net.Dial("tcp", "127.0.0.1:25"); err != nil {
		t.Skip("there is no mta running on 127.0.0.1")
	}
	if err := runner.SelfTest(); err != nil {
		t.Fatal(err)
	}
}

func TestMailProcessor_Process_Undocumented2Reply(t *testing.T) {
	if TestUndocumented2Message == "" {
		t.Skip()
	}
	runner := CommandRunner{
		CommandTimeoutSec: 5,
		ReplyMailClient: inet.MailClient{
			MTAHost:  "127.0.0.1",
			MTAPort:  25,
			MailFrom: "<EMAIL>",
		},
		Undocumented2: TestUndocumented2,
	}
	// Prepare a good processor
	runner.Processor = common.GetTestCommandProcessor()
	runner.Processor.Features.WolframAlpha = TestWolframAlpha
	runner.Processor.Features.LookupByTrigger[TestWolframAlpha.Trigger()] = &TestWolframAlpha
	if err := runner.Process([]byte(TestUndocumented2Message)); err != nil {
		t.Fatal(err)
	}
	// Real MTA is required for the self test
	if _, err := net.Dial("tcp", "127.0.0.1:25"); err != nil {
		t.Skip("there is no mta running on 127.0.0.1")
	}
	if err := runner.SelfTest(); err != nil {<commit_msg>fix compilation error in cmd_runner_test.go<commit_after>package mailcmd

import (
	"github.com/HouzuoGuo/laitos/daemon/common"
	"github.com/HouzuoGuo/laitos/inet"
	"net"
	"strings"
	"testing"
)

func TestMailProcessor_Process(t *testing.T) {
	runner := CommandRunner{
		Processor: &common.CommandProcessor{},
		ReplyMailClient: inet.MailClient{
			MTAHost:  "127.0.0.1",
			MTAPort:  25,
			MailFrom: "<EMAIL>",
		},
		Undocumented1: TestUndocumented1,
	}
	if err := runner.Initialise(); err == nil || strings.Index(err.Error(), "filters must be configured") == -1 {
		t.Fatal(err)
	}
	// CommandRunner has insane command processor
	runner.Processor = common.GetInsaneCommandProcessor()
	if err := runner.Initialise(); err == nil || strings.Index(err.Error(), "PIN is too short") == -1 {
		t.Fatal(err)
	}
	// Prepare a good processor
	runner.Processor = common.GetTestCommandProcessor()
	TestCommandRunner(&runner, t)
}

func TestMailProcessor_Process_Undocumented1Reply(t *testing.T) {
	if TestUndocumented1Message == "" {
		t.Skip()
	}
	runner := CommandRunner{
		ReplyMailClient: inet.MailClient{
			MTAHost:  "127.0.0.1",
			MTAPort:  25,
			MailFrom: "<EMAIL>",
		},
		Undocumented1: TestUndocumented1,
	}
	// Prepare a good processor
	runner.Processor = common.GetTestCommandProcessor()
	runner.Processor.Features.WolframAlpha = TestWolframAlpha
	runner.Processor.Features.LookupByTrigger[TestWolframAlpha.Trigger()] = &TestWolframAlpha
	if err := runner.Process([]byte(TestUndocumented1Message)); err != nil {
		t.Fatal(err)
	}
	// Real MTA is required for the self test
	if _, err := net.Dial("tcp", "127.0.0.1:25"); err != nil {
		t.Skip("there is no mta running on 127.0.0.1")
	}
	if err := runner.SelfTest(); err != nil {
		t.Fatal(err)
	}
}

func TestMailProcessor_Process_Undocumented2Reply(t *testing.T) {
	if TestUndocumented2Message == "" {
		t.Skip()
	}
	runner := CommandRunner{
		ReplyMailClient: inet.MailClient{
			MTAHost:  "127.0.0.1",
			MTAPort:  25,
			MailFrom: "<EMAIL>",
		},
		Undocumented2: TestUndocumented2,
	}
	// Prepare a good processor
	runner.Processor = common.GetTestCommandProcessor()
	runner.Processor.Features.WolframAlpha = TestWolframAlpha
	runner.Processor.Features.LookupByTrigger[TestWolframAlpha.Trigger()] = &TestWolframAlpha
	if err := runner.Process([]byte(TestUndocumented2Message)); err != nil {
		t.Fatal(err)
	}
	// Real MTA is required for the self test
	if _, err := net.Dial("tcp", "127.0.0.1:25"); err != nil {
		t.Skip("there is no mta running on 127.0.0.1")
	}
	if err := runner.SelfTest(); err != nil {
{'fraction_non_alphanumeric': 0.14525462962962962, 'fraction_numerical': 0.026041666666666668, 'mean_word_length': 4.334362139917696, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 14, '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': '6599177', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1863, 'n_words': 380}