📜 ⬆️ ⬇️

Sparrow - perl framework for testing and monitoring web applications

History of creation


Sparrow is a very young project. It originated as an add-on to the swat -DSL tool, written in perl to develop test scripts for various web applications. Description swat is a separate topic, which I will probably cover in the following publications, but, in a nutshell, swat is a tool for automating web testing, based on the use of the curl utility and allowing you to create arbitrary http requests and validate the returned content.

Install sparrow


We put as a normal cpan module.

$ sudo cpanm Sparrow 

After installation in the current PATH, the sparrow utility, the actual console client itself, provides the entire set of framework functions.

Ideology sparrow


Sparrow is designed as a simple console client that allows you to quickly set up and run tests for various web applications. There are two types of basic operations within the framework of this tool - the creation of a test structure and the installation, the launch of sparrow plug-ins.
')

Project sparrow structure


At the moment there are three main entities with which sparrow operates - projects, sites and plugins.

Projects are abstractions that allow you to describe groups of tested applications. The project has an identifier, a set of plug-ins and a set of tested sites. Here's how it might look in the console output when working with the sparrow utility. Display the structure of the project sparrow:

 $ sparrow project foo # sparrow environment initialzed at /home/vagrant/sparrow project foo info: [plugins] swat-mongodb-http swat-pintod swat-app-docsisious metacpan swat-lighttpd swat-yars swat-nginx [sites] mongodb-http-server [127.0.0.1:28017] pintod-server [127.0.0.1:3111] metacpan [http://metacpan.org] lighttpd [127.0.0.1:8080] thorsen [http://home.thorsen.pm/docsisious] yars_server [localhost:9001] localhost [127.0.0.1] 

From the above output, it can be understood that this project contains a set of plug-ins (mongodb-http-server, pintod-server, ...) for testing relevant applications and a set of sites, which will be discussed later.

Sparrow sites


Sites in sparrow describe an arbitrary test web application. In addition to the identifier, the site must have a base URL , which is the “root” URL for http requests that will come during the test run. In most cases, the base URL may be the same as the fqdn or IP address of the server of the application under test, and the specification of the scheme and the port is optional. To be precise, the base url must be compatible with the curl url format. It is also worth noting that despite the fact that curl allows interaction with other protocols (ftp, ...), sparrow in conjunction with swat is used only for testing applications using the http protocol.

Here is an example of creating a site in a sparrow project in the case of an application like nginx server:

 $ sparrow project foo add_site nginx-server 127.0.0.1 

Sparrow plugins


Plugins are the most interesting and promising feature of sparrow, making it a powerful tool for testing and monitoring web applications. Maybe I was looking badly, but I did not find something similar in other test automation tools, not only in the perl ecosystem, but also in other programming languages.

In a nutshell, a sparrow plugin is a portable test suite that you can install and run. A very clear analogy can be built on the example of various package managers, such as yum in centos or apt-get in debian. For different types of applications it should be possible to select and install a plugin that encapsulates a specific test suite that can be run for a given application.

At the moment, the list of sparrow plug-ins is very limited, but there is hope that members of the perl community will notice the project and soon we will be able to see many new plug-ins. Moreover, the process of writing a new plug-in is in most cases trivial and does not even require perl knowledge as such, but, I repeat, the disclosure of this topic is beyond the scope of my post and may be implemented in the future.

So, sparrow plugins can be installed and added to projects:

 $ sparrow plg list # sparrow environment initialzed at /home/vagrant/sparrow [sparrow plugins list] swat-yars | https://github.com/melezhik/swat-yars.git metacpan | https://github.com/CPAN-API/metacpan-monitoring.git swat-app-docsisious | https://github.com/melezhik/swat-app-docsisious.git swat-nginx | https://github.com/melezhik/swat-nginx.git swat-lighttpd | https://github.com/melezhik/swat-lighttpd.git swat-pintod | https://github.com/melezhik/swat-pintod.git swat-mongodb-http | https://github.com/melezhik/swat-mongodb-http.git 

Installing the plugin is currently implemented as a normal checkout from a remote git repository, perhaps in the future this functionality will be rewritten using our own sparrow repositories with versioning distributions and other conveniences, by analogy with the usual cpan repository.

 vagrant@Debian-jessie-amd64-netboot:~/projects/sparrow$ sparrow plg install swat-nginx # sparrow environment initialzed at /home/vagrant/sparrow installing plugin swat-nginx ... Cloning into 'swat-nginx'... .... Installing modules using /home/vagrant/sparrow/plugins/swat-nginx/cpanfile Successfully installed Outthentic-DSL-0.0.4 Successfully installed swat-0.1.68 2 distributions installed Complete! Modules were installed into /home/vagrant/sparrow/plugins/swat-nginx/local 

Having installed the plugin, you need to attach it to the project and then run the test suite using the selected site (web application) as an input parameter:

 $ sparrow project foo add_plg swat-nginx # sparrow environment initialzed at /home/vagrant/sparrow plugin swat-nginx is successfully added to project foo $ sparrow project foo check_site nginx-server swat-nginx # sparrow environment initialzed at /home/vagrant/sparrow /home/vagrant/.swat/.cache/3486/prove/00.GET.t .. ok 1 - GET 127.0.0.1/ succeeded # response saved to /home/vagrant/.swat/.cache/3486/prove/p3y5aUKFgj ok 2 - output match '200 OK' ok 3 - output match /Server: nginx\/(\S+)/ ok 4 - valid nginx version: 1.6.2 1..4 ok All tests successful. Files=1, Tests=4, 1 wallclock secs ( 0.01 usr 0.00 sys + 0.04 cusr 0.00 csys = 0.05 CPU) Result: PASS 

Conclusion


On this, our acquaintance with sparrow unfortunately ends, although, of course, there is still something to tell. As already mentioned, the project is still very young and is actively developing, as, incidentally, the main component for writing test scenarios is swat. It is hoped that the perl community, and all those who are close to automating the testing and monitoring processes will contribute to the history of the life of the still small but agile sparrow (*).

(*) - “sparrow” - in translation from English means a sparrow.

PS


I can not help but add a few important points, perhaps anticipating some of the issues that may arise after reading the article.

  1. Remote launch of tests via web api - this possibility is planned for implementation in the near future, bearing in mind the large number of systems that allow you to check the availability of web services through calls to external APIs, for example, the same consul or nagios .
  2. integration with existing systems of continuous integration and reporting - so on exit, after launching the sparrow plug-in, we get TAP , it is easy to write a parser that converts the results into other formats. I will say more: since sparrow triggers swat when launching plugins, which in turn uses perl prove to perform tests, this option for converting TAP into different formats is provided out of the box, well, or with minimal code writing, details can be found on the documentation page swat, in the "TAP" section.
  3. and, finally, quite a reasonable question - “where has this solution been tested (sparrow / swat)?” Swat has established itself as a very convenient way to quickly develop smoke tests for dozens of web applications in a short time during my daily work as an devops engineer . Sparrow is still being tested, but we can already say that this project is a logical continuation of swat, ac using sparrow plug-ins is a chance that it will be in demand with the web developers, devopos and system administrators.

Source: https://habr.com/ru/post/272245/


All Articles