func (ms *MainSuite) TestSizeCheck(c *C) {
	daylimit.LoadConfig("./config/config.yml")
	config := daylimit.Config()
	daylimit.InitLog("")
	warden = &daylimit.Warden{
		Bin:          config.WardenBin,
		BlockRate:    config.BlockRate,
		BlockBurst:   config.BlockRate,
		UnblockRate:  config.UnblockRate,
		UnblockBurst: config.UnblockRate,
	}

	SizeCheck("test", 1000)
	time.Sleep(time.Duration(config.FetchInterval) * time.Second)
	SizeCheck("test", 10000)
	c.Assert(items["test"].Status, Equals, int8(BLOCK))
	time.Sleep(time.Duration(config.LimitWindow+1) * time.Second)
	SizeCheck("test", 10000)
	c.Assert(items["test"].Status, Equals, int8(UNBLOCK))
}
Пример #2
0
func main() {
	flag.StringVar(&configFile, "c", "", "Config file name")
	flag.Parse()
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s -c config_file", os.Args[0])
		flag.PrintDefaults()
		os.Exit(2)
	}

	if configFile == "" {
		flag.Usage()
	}

	if err := daylimit.LoadConfig(configFile); err != nil {
		fmt.Fprintf(os.Stderr, "Load config file error: %s", err)
		os.Exit(2)
	}
	config := daylimit.Config()

	if f, err := os.Open(config.WardenBin); err != nil {
		fmt.Fprintf(os.Stderr, "Open warden bin file error: %s", err)
		flag.Usage()
	} else {
		f.Close()
	}

	warden = &daylimit.Warden{
		Bin:          config.WardenBin,
		BlockRate:    config.BlockRate,
		BlockBurst:   config.BlockRate,
		UnblockRate:  config.UnblockRate,
		UnblockBurst: config.UnblockRate,
	}

	daylimit.InitLog(config.LogFile)
	runDaemon()
}