Method for realizing self-defined end-to-end test case compilingTechnical Field
The invention relates to the technical field of cloud computing, in particular to a method for realizing self-defined end-to-end test case compiling.
Background
In recent years, cloud computing and various related technologies are vigorously developed, and the field of cloud computing is changing day by day. With the security, reliability and efficiency of cloud computing platforms in mind, more and more governments, enterprises and other various organizations choose to deploy their applications onto the cloud platforms. With the rapid development of cloud computing technology, verification and testing of cloud computing related software plays an increasingly important role in the reliability and safety of the software in the development and deployment processes of the cloud computing software. Because the cloud computing software is high in complexity and mostly has a distributed architecture, the testing difficulty is higher compared with other software. Especially, in the field of end-to-end testing in cloud computing, the method adopted by the traditional testing is still manual testing, the automation level is low, the time consumption is long, and the multiplexing cannot be realized.
The cloud computing platform is a distributed system and needs to work with other systems in various environments, and end-to-end testing plays an important role in such distributed systems. In this case, it needs to be checked in all aspects to ensure accurate interaction between different platforms and environments. The end-to-end test refers to that the application program and the dependent system are tested together during testing, and the smooth interaction between the front end and the back end of the program or between the upstream and the downstream is ensured, so that the closed loop is realized on the service, and the use requirements of customers are met.
Gitlab is an open source Git warehouse management software, and the version management of software projects can be realized by combining Git with the Gitlab.
Kubernets is an open source application for managing containers on multiple hosts in a cloud platform. Kubernets aims to make deploying containerized applications simple and efficient, and provides a mechanism for application deployment, planning, updating, and maintenance.
Docker is an open source application container engine that allows developers to package their applications and dependencies into a portable image and then distribute them to any popular Linux or Windows machine. The containers are completely sandboxed without any interface between them.
Sonobuoy is a kubernets cluster diagnostic tool. Sonobuoy can more easily understand the state of a kubernets cluster by running a series of configuration tests in an accessible and non-destructive manner.
The go test command is a program that tests code according to certain conventions and organizations. Within the package directory, all source files with a _ test. go suffix, when executing a go build, are not built into a part of the package, they are part of the go test. go test command will traverse all the functions meeting the naming rule in the _ test.
Disclosure of Invention
In order to solve the technical problems, the invention provides a method for realizing self-defined end-to-end test case compiling, which can simplify the operation of testers, realize the automation and the reuse of end-to-end test in a code mode, save the time and the labor cost and improve the working efficiency.
The technical scheme of the invention is as follows:
a method for realizing self-defined end-to-end test case compiling,
the method comprises the following steps:
a) planning Gitlab for end-to-end test case version management
b) Planning Sonobuoy to generate end-to-end test plug-in
c) Planning Sonobuoy to perform end-to-end testing
d) Planning Golang package to manage test cases of different components
e) Planning Docker constructs an end-to-end test image.
Further, in the above-mentioned case,
a) a user newly builds a folder corresponding to the test component under the project, then newly builds a star-go file under the folder, writes a test case in the star-go file, and submits a code to a gitlab warehouse after writing;
b) compiling the end-to-end test item by using go test to generate a binary file for testing;
c) using docker to make the binary file of the test generated in the last step into a mirror image, and packaging the required components;
d) and creating a Sonobuoy plug-in and running the mirror image created in the previous step. The end-to-end test case written by the tester is executed, and the execution result is output according to the corresponding format.
Further, in the above-mentioned case,
gitlab configuration
c) Creating a code repository as an item repository for end-to-end testing
d) End-to-end test cases are written according to test requirements, and codes are submitted to a mirror repository.
Docker configuration
d) Writing Dockerfile
e) Packaging binary test files, configuration files and corresponding components into a mirror image
f) Making mirror images and marking corresponding labels, and selecting whether to push the mirror images to a mirror image warehouse according to requirements
Sonobuoy configuration
a) Generating an add-in definition file by using a sonobuy gen plugin command;
b) running an end-to-end test by using a plug-in definition file and a docker mirror image;
c) and generating a test result and storing the test result to the local.
Further, in the above-mentioned case,
the end-to-end test item is written by using Go language; the functions of each folder and the files are as follows:
1) go.mod and go.sum files are files required for recording project dependent components;
2) e2e _ test.go and e2e.go are end-to-end test master files;
3) the api folder is used for storing the api of the component to be tested;
4) the components folder is used for placing test cases of different components;
5) the utils are used for storing tools required by executing the test cases;
6) and storing end-to-end test item dependencies under the vendor.
The function of the main functions of the test case template is as follows:
1) descripte: classifying one or more test cases to describe a behavior or a method;
2) context: adding conditional statements to cover various conditions as completely as possible;
3) it: the contained code is a test case.
The Sonobutoy commands function as follows:
1) the sonobuoy gen plugin is used for generating a yaml file for pulling up an end-to-end test plug-in;
-name is the plug-in name, -image is the mirror image of the executing plug-in;
2) the sonobuoy run is used to execute plug-ins for end-to-end testing; -p is the name of the plug-in
Image-pull-policy is a mirror pull policy.
The invention has the advantages that
The invention realizes a method for compiling the user-defined end-to-end test case on kubernets, and provides a whole set of solution for end-to-end test. The end-to-end test is changed from the prior manual test into the prior automatic test, the test multiplexing is realized, the working efficiency of a test engineer is improved, and the test engineer can better understand the tested project and improve the technical level of the test engineer.
Drawings
FIG. 1 is a schematic workflow diagram of the present invention;
fig. 2 is a schematic diagram of a file structure.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer and more complete, the technical solutions in the embodiments of the present invention will be described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention, and based on the embodiments of the present invention, all other embodiments obtained by a person of ordinary skill in the art without creative efforts belong to the scope of the present invention.
The invention provides an integrated solution of end-to-end test based on the sonobuoy and the golang test.
The workflow is shown in fig. 1. The flow of the user-defined end-to-end test case compiling method is as follows:
a) and a user newly builds a folder corresponding to the test component under the project, then newly builds a star-go file under the folder, writes a test case in the star-go file, and submits a code to a gitlab warehouse after writing. The file structure is shown in fig. 2.
b) Compiling end-to-end test items using go test to generate binary files for testing
c) Using docker to make the binary file of the test generated in the last step into a mirror image, and packaging the required components
d) And creating a Sonobuoy plug-in and running the mirror image created in the previous step. The end-to-end test case written by the tester is executed, and the execution result is output according to the corresponding format.
Gitlab configuration
e) Creating a code repository as an item repository for end-to-end testing
f) End-to-end test case is compiled according to test requirements, and codes are submitted to a mirror repository
(II) Docker configuration
g) Writing Dockerfile
h) Packaging binary test files, configuration files and corresponding components into a mirror image
i) Making mirror images and marking corresponding labels, and selecting whether to push the mirror images to a mirror image warehouse according to requirements
(III) Sonobuoy configuration
a) Generating plug-in definition file using the Sonobuoy gen plugin command
b) An end-to-end test is run using the plug-in definition file and the docker image.
c) And generating a test result and storing the test result to the local.
End-to-end test item structure
The end-to-end test project is written by using Go language, and the project structure is shown in fig. 2. The functions of each folder and the files are as follows:
the go.mod and go.sum files are files required to record project dependent components.
2, e2e _ test.go and e2e.go are end-to-end test master files
The api folder is used for storing the api of the component to be tested
The components folder is used for placing test cases of different components.
Utils for storing tools required for executing test cases
End-to-end test item dependency for storage under vendor
End-to-end test case template sample
As shown above for the test case template, the main functions function as follows:
descripte: classifying one or more test cases to describe a behavior or a method
Context: adding conditional statements to cover various conditions as completely as possible
And 3, It: the code contained is a test case
Sonobuoy production and startup plug-in example
The Sonobutoy commands function as follows:
sonobuoy gen plugin is used to generate the yaml file that pulls up the end-to-end test plug-in. - -name
Is the plug-in name, image is the mirror image of the executing plug-in.
Sonobuoy run was used to execute the plug-ins for end-to-end testing. -p is the name of the plug-in
Image-pull-policy is a mirror pull policy.
The above description is only a preferred embodiment of the present invention, and is only used to illustrate the technical solutions of the present invention, and not to limit the protection scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.