예제 #1
0
func TestSetup(t *testing.T) {
	go fakeServer(t)

	var conn Connection
	conn.Setup(fakeDispatcher, "TestNet", dyncfg.New(configLookupHelper))

	time.Sleep(2 * time.Second)

	conn.Quit <- struct{}{}

	// since we tested a reconnect, we should expect actual results to be
	// multipled
	setupMutex.Lock()
	actualExpectedOutput := append(expectedOutput, expectedOutput...)
	actualExpectedInput := append(input, input...)
	setupMutex.Unlock()

	setupMutex.Lock()
	defer setupMutex.Unlock()
	if fmt.Sprintf("%+v", actualExpectedOutput) != fmt.Sprintf("%+v", actualOutput) {
		t.Log("Expected output does not match actual output")
		t.Logf("expected: %+v\n", actualExpectedOutput)
		t.Logf("actual  : %+v\n", actualOutput)
		t.Fail()
	}

	if fmt.Sprintf("%+v", actualExpectedInput) != fmt.Sprintf("%+v", actualInput) {
		t.Log("Expected input does not match actual input")
		t.Logf("expected: %+v\n", actualExpectedInput)
		t.Logf("actual  : %+v\n", actualInput)
		t.Fail()
	}
}
예제 #2
0
func main() {
	var exit chan struct{}
	context := make(map[string]string)

	if len(os.Args) < 2 {
		log.Fatalln("Usage:", os.Args[0], "<configuration directory>")
	}

	d, err := os.Stat(os.Args[1])
	if err != nil {
		log.Fatalln("Error reading configuration from", os.Args[1], "error:", err.Error())
	}
	if !d.IsDir() {
		log.Fatalln("Not a directory:", os.Args[1])
	}

	cfg := dyncfg.New(fileListFuncBuilder(os.Args[1], "common.json"))

	logfile, err := os.OpenFile(cfg.LookupString(context, "Logpath"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
	if err != nil {
		log.Fatalln("Error opening", cfg.LookupString(context, "Logpath"), "for writing, error:", err.Error())
	}
	log.SetOutput(logfile)

	networks := cfg.LookupStringSlice(context, "Networks")

	log.Println("Configured networks:", len(networks), networks)

	bot.Initialize(cfg)
	for i, conn := range make([]irc.Connection, len(networks)) {
		conn := conn
		log.Println("Setting up", networks[i], "connection")
		conn.Setup(bot.Dispatcher, networks[i], cfg)
	}
	<-exit
}
예제 #3
0
func init() {
	Initialize(dyncfg.New(configLookupHelper))
}