Other(test): Ensure calls are protected by mutex

This commit is contained in:
James Houlahan
2022-10-25 10:26:34 +02:00
parent 3e54885ea0
commit 5adbf74cbe

View File

@ -22,6 +22,7 @@ import (
"crypto/tls"
"net/http"
"os"
"sync"
"testing"
"time"
@ -133,9 +134,15 @@ func TestBridge_Focus(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) {
var calls []server.Call
var (
calls []server.Call
lock sync.Mutex
)
s.AddCallWatcher(func(call server.Call) {
lock.Lock()
defer lock.Unlock()
calls = append(calls, call)
})
@ -150,6 +157,9 @@ func TestBridge_UserAgent(t *testing.T) {
_, err := bridge.LoginFull(context.Background(), username, password, nil, nil)
require.NoError(t, err)
lock.Lock()
defer lock.Unlock()
// Assert that the user agent was sent to the API.
require.Contains(t, calls[len(calls)-1].RequestHeader.Get("User-Agent"), bridge.GetCurrentUserAgent())
})