ooni-probe-cli/internal/engine/experiment/ndt7/upload_test.go
Simone Basso d922bd9afc
cleanup: mark more integration tests as !short mode (#755)
The objective is to make PR checks run much faster.

See https://github.com/ooni/probe/issues/2113 for context.

Regarding netxlite's tests:

Checking for every commit on master or on a release branch is
good enough and makes pull requests faster than one minute since
netxlite for windows is now 1m slower than coverage.

We're losing some coverage but coverage from integration tests
is not so good anyway, so I'm not super sad about this loss.
2022-05-24 21:01:15 +02:00

93 lines
2.0 KiB
Go

package ndt7
import (
"context"
"errors"
"testing"
"time"
"github.com/gorilla/websocket"
)
func TestUploadSetWriteDeadlineFailure(t *testing.T) {
expected := errors.New("mocked error")
mgr := newUploadManager(
&mockableConnMock{
WriteDeadlineErr: expected,
},
defaultCallbackPerformance,
)
err := mgr.run(context.Background())
if !errors.Is(err, expected) {
t.Fatal("not the error we expected")
}
}
func TestUploadNewMessageFailure(t *testing.T) {
expected := errors.New("mocked error")
mgr := newUploadManager(
&mockableConnMock{},
defaultCallbackPerformance,
)
mgr.newMessage = func(int) (*websocket.PreparedMessage, error) {
return nil, expected
}
err := mgr.run(context.Background())
if !errors.Is(err, expected) {
t.Fatal("not the error we expected")
}
}
func TestUploadWritePreparedMessageFailure(t *testing.T) {
expected := errors.New("mocked error")
mgr := newUploadManager(
&mockableConnMock{
WritePreparedMessageErr: expected,
},
defaultCallbackPerformance,
)
err := mgr.run(context.Background())
if !errors.Is(err, expected) {
t.Fatal("not the error we expected")
}
}
func TestUploadWritePreparedMessageSubsequentFailure(t *testing.T) {
expected := errors.New("mocked error")
mgr := newUploadManager(
&mockableConnMock{},
defaultCallbackPerformance,
)
var already bool
mgr.newMessage = func(int) (*websocket.PreparedMessage, error) {
if !already {
already = true
return new(websocket.PreparedMessage), nil
}
return nil, expected
}
err := mgr.run(context.Background())
if !errors.Is(err, expected) {
t.Fatal("not the error we expected")
}
}
func TestUploadLoop(t *testing.T) {
if testing.Short() {
t.Skip("skip test in short mode")
}
mgr := newUploadManager(
&mockableConnMock{},
defaultCallbackPerformance,
)
mgr.newMessage = func(int) (*websocket.PreparedMessage, error) {
return new(websocket.PreparedMessage), nil
}
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := mgr.run(ctx)
if err != nil {
t.Fatal(err)
}
}