Ejemplo n.º 1
0
func runCli(c *cli.Context) {

	// seed
	seed := c.Int("seed")
	// requests
	requests := c.Int("requests")

	// workers
	workers := c.Int("workers")
	if workers < 1 {
		fmt.Println("workers flag must be a positive integer greater than zero")
		os.Exit(1)
	}

	// method
	method := c.String("method")

	// body
	body := c.String("body")
	bodyBytes := []byte(body)
	if bodyBytes == nil || len(bodyBytes) == 0 {
		fmt.Println("body flag has no value")
		os.Exit(1)
	}

	// urls
	urls := c.StringSlice("urls")
	if urls == nil || len(urls) == 0 {
		fmt.Println("no urls specified")
		os.Exit(1)
	}

	runConf, err := client.NewRunConf(
		uint32(workers),
		uint32(requests),
		method,
		map[string]string{"": ""},
		&client.URLRandomizer{
			IntVars:    GlobalIntVars,
			StringVars: GlobalStringVars,
			Seed:       int64(seed),
			Urls:       urls},
		bodyBytes,
	)

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	runConf.Exec()
}
Ejemplo n.º 2
0
func initJson(c *cli.Context) {
	if len(c.Args()) != 1 {
		fmt.Println("error: expecting one argument")
		os.Exit(1)
	}

	fileName := c.Args()[0]

	tmpUrls := []string{"http://localhost:8080/{1}/{2}.html"}
	tmpVals := []string{"index", "about", "contact"}
	tmpIntVars := []*client.IntVar{&client.IntVar{"{1}", 0, 42}}
	tmpStrVals := []*client.StringVar{&client.StringVar{"{2}", tmpVals}}
	profile, err := client.NewRunConf(
		uint32(100),
		uint32(8),
		"GET",
		map[string]string{"": ""},
		&client.URLRandomizer{0, tmpUrls, tmpIntVars, tmpStrVals},
		nil)
	if err != nil {
		fmt.Println("this shouldn't happen")
		os.Exit(1)
	}

	bytes, err := json.MarshalIndent(profile, "", "   ")
	if err != nil {
		fmt.Println("error encoding json: ", err)
		os.Exit(1)
	}
	err = ioutil.WriteFile(fileName, bytes, 0644)
	if err != nil {
		fmt.Println("error saving json to ", fileName, ": ", err)
		os.Exit(1)
	}
	os.Exit(0)
}