mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-18 08:06:59 +00:00
Other(test): Ensure calls are protected by mutex
This commit is contained in:
@ -22,6 +22,7 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -133,9 +134,15 @@ func TestBridge_Focus(t *testing.T) {
|
|||||||
|
|
||||||
func TestBridge_UserAgent(t *testing.T) {
|
func TestBridge_UserAgent(t *testing.T) {
|
||||||
withEnv(t, func(ctx context.Context, s *server.Server, netCtl *liteapi.NetCtl, locator bridge.Locator, vaultKey []byte) {
|
withEnv(t, func(ctx context.Context, s *server.Server, netCtl *liteapi.NetCtl, locator bridge.Locator, vaultKey []byte) {
|
||||||
var calls []server.Call
|
var (
|
||||||
|
calls []server.Call
|
||||||
|
lock sync.Mutex
|
||||||
|
)
|
||||||
|
|
||||||
s.AddCallWatcher(func(call server.Call) {
|
s.AddCallWatcher(func(call server.Call) {
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
|
||||||
calls = append(calls, call)
|
calls = append(calls, call)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -150,6 +157,9 @@ func TestBridge_UserAgent(t *testing.T) {
|
|||||||
_, err := bridge.LoginFull(context.Background(), username, password, nil, nil)
|
_, err := bridge.LoginFull(context.Background(), username, password, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
|
||||||
// Assert that the user agent was sent to the API.
|
// Assert that the user agent was sent to the API.
|
||||||
require.Contains(t, calls[len(calls)-1].RequestHeader.Get("User-Agent"), bridge.GetCurrentUserAgent())
|
require.Contains(t, calls[len(calls)-1].RequestHeader.Get("User-Agent"), bridge.GetCurrentUserAgent())
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user