-
Notifications
You must be signed in to change notification settings - Fork 0
Testing
Our test system base on end 2 end (e2e) test as main tests, and unit tests as secondary tests. Our unit tests testing only small code that rarely changes.
There are reasons for this:
- Kneesocks changes very often, fixing unit tests for every changed file will cost too much time.
- E2e tests the end result, which will not change. So, e2e tests will not need to be changed every time the code changes.
- Write e2e tests is easier than writing unit tests for each file and class, it costs much less time and not that boring.
Our e2e tests consists of 3 programs which run simultaneously:
- Kneesocks socks server with appropriate configuration.
Kneesocks socks server is the server that will be tested.
- Test server.
Test server is just tcp/udp server that will send pictures in response from request. Each connection or packet will be relayed by socks server (except testing bind command).
There are 3 types of picture, all with different size:
-
1- The biggest picture with size35.4MBfor testing big data transfers. -
2- Picture with middle size94.5KBfor testing middle data transfers. -
3- Picture with small size14KBfor testing small data transfers.
All pictures by default downloads to /tmp directory. If test succeeds picture will be deleted, if test fails picture will not be deleted.
After transferring the picture stand compares hash of actual picture and transferred picture.
- E2e tests stand.
E2e test stand compares actual responses from server with expected responses, also it compares hash of received pictures.
NOTE: We not using docker during tests, so you will need to build binaries yourself.
First you need to choose directory where you will clone the sources. Suppose that it will be /tmp.
cd /tmp && git clone https://github.com/chop1k/kneesocks && cd kneesocksThen you need to build executable from sources, golang will automatically download all dependencies.
go build -i -o kneesocks cmd/kneesocks/main.goWe recommend use our testing config during testing.
First you need test server binary, if not have one you need to build it yourself.
You also need the config, you can make your own or use default config that we using during local testing. For more information read appropriate section of the wiki.
NOTE: By default config for test server located at /etc/kneesocks/test-server-config.json, but you can override it using config_path environment variable.
git clone https://github.com/chop1k/kneesocks && cd kneesocksgo build -i -o test_server cmd/test_server/main.goAnd then you need to start the server.
./test_serverIt will print something like this.
2022-02-17 11:07:57 INF Udp server listening. address=:9999
2022-02-17 11:07:57 INF Connect tcp server listening. address=:9999
2022-02-17 11:07:57 INF Bind tcp server listening. address=:9000
Before you execute tests, you will need config. You should use default. You can read config reference if you need more info about config.
Clone the repository.
git clone https://github.com/chop1k/kneesocks && cd kneesocksExecute tests.
go test -c -o e2e.test socks/test/e2eMake sure that you started socks server and test server. Make sure that config is correct, all addresses and ports are valid.
Our unit tests tests only code that rarely changes or code that very primitive and not complex.
Start protocol tests. Protocol tests tests protocol chunks like request chunk, selection chunk, password chunk, it tests chunk builders, chunk parsers, etc.
go test -c -o /tmp/password.test socks/pkg/protocol/auth/password && /tmp/password.testgo test -c -o /tmp/v4.test socks/pkg/protocol/v4 && /tmp/v4.testgo test -c -o /tmp/v4a.test socks/pkg/protocol/v4a && /tmp/v4a.testgo test -c -o /tmp/v5.test socks/pkg/protocol/v5 && /tmp/v5.testStart managers tests. Managers is objects that contains global map, like map with address associations for udp and bind commands.
go test -c -o /tmp/managers.test socks/internal/kneesocks/managers && /tmp/managers.test