httpbot

Github.com/pojol/httpb…

What does this framework do for you

  1. Before and after the separationIn our development process, the back end provides a lot of APIS for the client (front end) to call, and if there is no self-testing tool, relying on client testing is obviously very inefficient
  2. reusableThe tests written in the development process are usually not so happy. Through this tool, we can reuse the test cases in the development process as much as possible, such as integration into CI implementationThe API testOr implementPressure testTo invoke different test strategies in different situations (such as executing a specific mail test process in a mail service CI, and so on)
  3. Can be injected intoWe can inject in use cases during testingDifferent parameters, can also be injectedassertionsUsed to detect the results of tests
  4. Multiple drive modelIn this framework, we can launch several robots for testing at one time, or set up several robots per second, set the life cycle of the factory, etc. At the same time, we can also test for a single robot (by setting the factory metadata passed into the policy
  5. The reportThrough the test report integrated by the framework, we can easily see the parameters in each test, such as QPS, and also use it when there is an errorredLogs are marked prominently (factory can also be set to stop (or continue execution) immediately if an error is detected

features

  • reusableAfter defining an HTTP request, we can reuse this definition in any policy (request parameters can be changed by injection)
  • logicCan be arranged, we can orchestrate the tests into different strategies, and then conduct individual tests for specific scenarios.
  • Provide factory methods that users can adoptMultiple drive modelConduct tests so that you can conduct your own tests in different scenarios. (C->S self-testing, integration in CI steps for API testing, stress testing, etc…

component

  • Prefabricated stage
    • Metadata is used to store variables used by the Bot throughout its life cycle.
    • Card Packaging of HTTP requests
  • Choreography, stage
    • Timeline Specifies the Timeline that drives the logical execution sequence
    • StepUsed to encapsulate different behaviors of bots. At this stage, you can injectparameterassertionsTo control behavioral logic and detect right and wrong
    • Strategy provides methods for Bot creation and behavior choreography (mainly integrating STEPS)
  • Driver stage
    • Factory is used to batch create bots

Quick start


bf, _ := factory.Create(
	factory.WithCreateNum(0),	// run all strategy
	factory.WithLifeTime(time.Minute),
	factory.WithRunMode(factory.FactoryModeStatic),
	factory.WithMatchUrl([]string{
		"/v1/login/guest"."/v1/base/account.info"}),)defer bf.Close()

bf.Append("default strategy".func(url string, client *http.Client) *httpbot.Bot {
	md, err := rprefab.NewBotData()
	iferr ! =nil {
		panic(err)
	}

	bot := httpbot.New(md, 
		client, 
		httpbot.WithName("default bot"))

	defaultStep := prefab.NewStep()

	guestLoginCard := prefab.NewGuestLoginCard(md)
	guestLoginCard.Base.InjectAssert("token assert".func(a) error {
		return assert.NotEqual(md.Token, "")
	})
	defaultStep.AddCard(guestLoginCard)

	bot.Timeline.AddStep(step)

	return bot
})

bf.Run()

Copy the code

Output preview

/v1/login/guest Req count 1 Consume 26ms Succ rate 1/1 0kb / 0kb +---------------------------------------------------------------------------------------+ Req url Req count Average time  Succ rate /v1/login/guest 1 26ms 1/1 0kb / 0kb +---------------------------------------------------------------------------------------+ robot : 1 req count : 1 duration : 1s qps : 1 errors : 0 /v1/base/account.info not match coverage 1 / 2Copy the code