urlgetter: fix tunnel test (#299)

* urlgetter: fix tunnel test

This diff fixes the urlgetter test suite to make sure we
are correctly testing for tunnel creation.

While there, improve the way in which we create a testing
directory and add a test for that.

Part of https://github.com/ooni/probe/issues/985.

* fix comment

* fix comment
This commit is contained in:
Simone Basso 2021-04-05 18:25:43 +02:00 committed by GitHub
commit 6aa2551c43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 845 additions and 749 deletions

View file

@ -40,6 +40,16 @@ func (t *fakeTunnel) SOCKS5ProxyURL() *url.URL {
// fakeStart starts the fake tunnel.
func fakeStart(ctx context.Context, config *Config) (Tunnel, error) {
// do the same things other tunnels do:
//
// 1. abort if context is cancelled
//
// 2. check for tunnelDir being not empty
//
// 3. attempt to create tunnelDir
//
// after that, it's all fake and we just create a simple
// socks5 server that we can use
select {
case <-ctx.Done():
return nil, ctx.Err() // simplifies unit testing this code
@ -48,6 +58,9 @@ func fakeStart(ctx context.Context, config *Config) (Tunnel, error) {
if config.TunnelDir == "" {
return nil, ErrEmptyTunnelDir
}
if err := config.mkdirAll(config.TunnelDir, 0700); err != nil {
return nil, err
}
server, err := config.socks5New(&socks5.Config{})
if err != nil {
return nil, err