mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2026-03-14 14:35:44 +01:00
Improve use of testify assertions.
This commit is contained in:
parent
b8e0e5c2c1
commit
d8d17734cb
20 changed files with 119 additions and 110 deletions
|
|
@ -524,7 +524,7 @@ func TestFilterSDPCandidates(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
assert.EqualValues(expectedBefore[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
assert.Equal(expectedBefore[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
}
|
||||
|
||||
blocked, err := ParseAllowedIps("192.0.0.0/24, 192.168.0.0/16")
|
||||
|
|
@ -542,7 +542,7 @@ func TestFilterSDPCandidates(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
assert.EqualValues(expectedAfter[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
assert.Equal(expectedAfter[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -574,7 +574,7 @@ func TestNoFilterSDPCandidates(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
assert.EqualValues(expectedBefore[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
assert.Equal(expectedBefore[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
}
|
||||
|
||||
blocked, err := ParseAllowedIps("192.0.0.0/24, 192.168.0.0/16")
|
||||
|
|
@ -592,7 +592,7 @@ func TestNoFilterSDPCandidates(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
assert.EqualValues(expectedAfter[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
assert.Equal(expectedAfter[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,12 +74,13 @@ func TestPostOnRedirect(t *testing.T) {
|
|||
http.Redirect(w, r, "/ocs/v2.php/two", http.StatusTemporaryRedirect)
|
||||
})
|
||||
r.HandleFunc("/ocs/v2.php/two", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert := assert.New(t)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
|
||||
var request map[string]string
|
||||
err = json.Unmarshal(body, &request)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
|
||||
returnOCS(t, w, body)
|
||||
})
|
||||
|
|
@ -160,9 +161,10 @@ func TestPostOnRedirectStatusFound(t *testing.T) {
|
|||
})
|
||||
r.HandleFunc("/ocs/v2.php/two", func(w http.ResponseWriter, r *http.Request) {
|
||||
body, err := io.ReadAll(r.Body)
|
||||
require.NoError(err)
|
||||
if assert.NoError(err) {
|
||||
assert.Empty(string(body), "Should not have received any body, got %s", string(body))
|
||||
}
|
||||
|
||||
assert.Empty(string(body), "Should not have received any body, got %s", string(body))
|
||||
returnOCS(t, w, []byte("{}"))
|
||||
})
|
||||
server := httptest.NewServer(r)
|
||||
|
|
|
|||
|
|
@ -1316,7 +1316,7 @@ func TestBackendServer_TurnCredentials(t *testing.T) {
|
|||
m.Write([]byte(cred.Username)) // nolint
|
||||
password := base64.StdEncoding.EncodeToString(m.Sum(nil))
|
||||
assert.Equal(password, cred.Password)
|
||||
assert.EqualValues((24 * time.Hour).Seconds(), cred.TTL)
|
||||
assert.InEpsilon((24 * time.Hour).Seconds(), cred.TTL, 0.0001)
|
||||
assert.Equal(turnServers, cred.URIs)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ import (
|
|||
|
||||
func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*CapabilitiesResponse, http.ResponseWriter) error) (*url.URL, *Capabilities) {
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
pool, err := NewHttpClientPool(1, false)
|
||||
require.NoError(err)
|
||||
capabilities, err := NewCapabilities("0.0", pool)
|
||||
|
|
@ -79,7 +80,7 @@ func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*Capabilitie
|
|||
"features": features,
|
||||
"config": config,
|
||||
})
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
emptyArray := []byte("[]")
|
||||
response := &CapabilitiesResponse{
|
||||
Version: CapabilitiesVersion{
|
||||
|
|
@ -92,7 +93,7 @@ func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*Capabilitie
|
|||
}
|
||||
|
||||
data, err := json.Marshal(response)
|
||||
assert.NoError(t, err, "Could not marshal %+v", response)
|
||||
assert.NoError(err, "Could not marshal %+v", response)
|
||||
|
||||
var ocs OcsResponse
|
||||
ocs.Ocs = &OcsBody{
|
||||
|
|
@ -104,7 +105,7 @@ func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*Capabilitie
|
|||
Data: data,
|
||||
}
|
||||
data, err = json.Marshal(ocs)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
|
||||
var cc []string
|
||||
if !strings.Contains(t.Name(), "NoCache") {
|
||||
|
|
|
|||
|
|
@ -38,10 +38,10 @@ func TestCounterWriter(t *testing.T) {
|
|||
w: &b,
|
||||
counter: &written,
|
||||
}
|
||||
if count, err := w.Write(nil); assert.NoError(err) && assert.EqualValues(0, count) {
|
||||
assert.EqualValues(0, written)
|
||||
if count, err := w.Write(nil); assert.NoError(err) && assert.Equal(0, count) {
|
||||
assert.Equal(0, written)
|
||||
}
|
||||
if count, err := w.Write([]byte("foo")); assert.NoError(err) && assert.EqualValues(3, count) {
|
||||
assert.EqualValues(3, written)
|
||||
if count, err := w.Write([]byte("foo")); assert.NoError(err) && assert.Equal(3, count) {
|
||||
assert.Equal(3, written)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ func TestBandwidth_Backend(t *testing.T) {
|
|||
u, err := url.Parse(server.URL + "/one")
|
||||
require.NoError(err)
|
||||
backend := hub.backend.GetBackend(u)
|
||||
require.NotNil(t, backend, "Could not get backend")
|
||||
require.NotNil(backend, "Could not get backend")
|
||||
|
||||
backend.maxScreenBitrate = 1000
|
||||
backend.maxStreamBitrate = 2000
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ func Test_Federation(t *testing.T) {
|
|||
|
||||
// Leaving and re-joining a room as "direct" session will trigger correct events.
|
||||
if room, ok := client1.JoinRoom(ctx, ""); ok {
|
||||
assert.Equal("", room.Room.RoomId)
|
||||
assert.Empty(room.Room.RoomId)
|
||||
}
|
||||
|
||||
client2.RunUntilLeft(ctx, hello1.Hello)
|
||||
|
|
@ -225,7 +225,7 @@ func Test_Federation(t *testing.T) {
|
|||
|
||||
// Leaving and re-joining a room as "federated" session will trigger correct events.
|
||||
if room, ok := client2.JoinRoom(ctx, ""); ok {
|
||||
assert.Equal("", room.Room.RoomId)
|
||||
assert.Empty(room.Room.RoomId)
|
||||
}
|
||||
|
||||
client1.RunUntilLeft(ctx, &HelloServerMessage{
|
||||
|
|
@ -485,7 +485,7 @@ func Test_Federation(t *testing.T) {
|
|||
}, hello3.Hello, hello4.Hello)
|
||||
|
||||
if room3, ok := client2.JoinRoom(ctx, ""); ok {
|
||||
assert.Equal("", room3.Room.RoomId)
|
||||
assert.Empty(room3.Room.RoomId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1043,7 +1043,7 @@ func Test_FederationResumeNewSession(t *testing.T) {
|
|||
// session and get "joined" events for all sessions in the room (including
|
||||
// its own).
|
||||
if message, ok := client2.RunUntilMessage(ctx); ok {
|
||||
assert.Equal("", message.Id)
|
||||
assert.Empty(message.Id)
|
||||
require.Equal("room", message.Type)
|
||||
require.Equal(federatedRoomId, message.Room.RoomId)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ func TestGeoLookupContinent(t *testing.T) {
|
|||
t.Run(country, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
continents := LookupContinents(country)
|
||||
if !assert.Equal(t, len(expected), len(continents), "Continents didn't match for %s: got %s, expected %s", country, continents, expected) {
|
||||
if !assert.Len(t, continents, len(expected), "Continents didn't match for %s: got %s, expected %s", country, continents, expected) {
|
||||
return
|
||||
}
|
||||
for idx, c := range expected {
|
||||
|
|
|
|||
32
hub_test.go
32
hub_test.go
|
|
@ -341,22 +341,22 @@ func WaitForHub(ctx context.Context, t *testing.T, h *Hub) {
|
|||
|
||||
func validateBackendChecksum(t *testing.T, f func(http.ResponseWriter, *http.Request, *BackendClientRequest) *BackendClientResponse) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
|
||||
rnd := r.Header.Get(HeaderBackendSignalingRandom)
|
||||
checksum := r.Header.Get(HeaderBackendSignalingChecksum)
|
||||
if rnd == "" || checksum == "" {
|
||||
require.Fail("No checksum headers found", "request to %s", r.URL)
|
||||
assert.Fail("No checksum headers found", "request to %s", r.URL)
|
||||
}
|
||||
|
||||
if verify := CalculateBackendChecksum(rnd, body, testBackendSecret); verify != checksum {
|
||||
require.Fail("Backend checksum verification failed", "request to %s", r.URL)
|
||||
assert.Fail("Backend checksum verification failed", "request to %s", r.URL)
|
||||
}
|
||||
|
||||
var request BackendClientRequest
|
||||
require.NoError(json.Unmarshal(body, &request))
|
||||
assert.NoError(json.Unmarshal(body, &request))
|
||||
|
||||
response := f(w, r, &request)
|
||||
if response == nil {
|
||||
|
|
@ -365,7 +365,7 @@ func validateBackendChecksum(t *testing.T, f func(http.ResponseWriter, *http.Req
|
|||
}
|
||||
|
||||
data, err := json.Marshal(response)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
|
||||
if r.Header.Get("OCS-APIRequest") != "" {
|
||||
var ocs OcsResponse
|
||||
|
|
@ -378,7 +378,7 @@ func validateBackendChecksum(t *testing.T, f func(http.ResponseWriter, *http.Req
|
|||
Data: data,
|
||||
}
|
||||
data, err = json.Marshal(ocs)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
|
@ -745,7 +745,7 @@ func registerBackendHandlerUrl(t *testing.T, router *mux.Router, url string) {
|
|||
if (strings.Contains(t.Name(), "V2") && !skipV2) || strings.Contains(t.Name(), "Federation") {
|
||||
key := getPublicAuthToken(t)
|
||||
public, err := x509.MarshalPKIXPublicKey(key)
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
var pemType string
|
||||
if strings.Contains(t.Name(), "ECDSA") {
|
||||
pemType = "ECDSA PUBLIC KEY"
|
||||
|
|
@ -794,7 +794,7 @@ func registerBackendHandlerUrl(t *testing.T, router *mux.Router, url string) {
|
|||
Data: data,
|
||||
}
|
||||
data, err = json.Marshal(ocs)
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(data) // nolint
|
||||
|
|
@ -1370,7 +1370,7 @@ func TestSessionIdsUnordered(t *testing.T) {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
|
||||
defer cancel()
|
||||
|
||||
_, hello := NewTestClientWithHello(ctx, t, server, hub, testDefaultUserId)
|
||||
_, hello := NewTestClientWithHello(ctx, t, server, hub, testDefaultUserId) // nolint:testifylint
|
||||
assert.Equal(testDefaultUserId, hello.Hello.UserId, "%+v", hello.Hello)
|
||||
assert.NotEmpty(hello.Hello.SessionId, "%+v", hello.Hello)
|
||||
|
||||
|
|
@ -2603,7 +2603,7 @@ func TestJoinRoom(t *testing.T) {
|
|||
|
||||
// Leave room.
|
||||
roomMsg = MustSucceed2(t, client.JoinRoom, ctx, "")
|
||||
require.Equal("", roomMsg.Room.RoomId)
|
||||
require.Empty(roomMsg.Room.RoomId)
|
||||
}
|
||||
|
||||
func TestJoinRoomBackendBandwidth(t *testing.T) {
|
||||
|
|
@ -2849,7 +2849,7 @@ func TestExpectAnonymousJoinRoomAfterLeave(t *testing.T) {
|
|||
|
||||
// Leave room
|
||||
roomMsg = MustSucceed2(t, client.JoinRoom, ctx, "")
|
||||
require.Equal("", roomMsg.Room.RoomId)
|
||||
require.Empty(roomMsg.Room.RoomId)
|
||||
|
||||
// Perform housekeeping in the future, this will cause the connection to
|
||||
// be terminated because the anonymous client didn't join a room.
|
||||
|
|
@ -2894,7 +2894,7 @@ func TestJoinRoomChange(t *testing.T) {
|
|||
|
||||
// Leave room.
|
||||
roomMsg = MustSucceed2(t, client.JoinRoom, ctx, "")
|
||||
require.Equal("", roomMsg.Room.RoomId)
|
||||
require.Empty(roomMsg.Room.RoomId)
|
||||
}
|
||||
|
||||
func TestJoinMultiple(t *testing.T) {
|
||||
|
|
@ -2928,13 +2928,13 @@ func TestJoinMultiple(t *testing.T) {
|
|||
|
||||
// Leave room.
|
||||
roomMsg = MustSucceed2(t, client1.JoinRoom, ctx, "")
|
||||
require.Equal("", roomMsg.Room.RoomId)
|
||||
require.Empty(roomMsg.Room.RoomId)
|
||||
|
||||
// The second client will now receive a "left" event
|
||||
client2.RunUntilLeft(ctx, hello1.Hello)
|
||||
|
||||
roomMsg = MustSucceed2(t, client2.JoinRoom, ctx, "")
|
||||
require.Equal("", roomMsg.Room.RoomId)
|
||||
require.Empty(roomMsg.Room.RoomId)
|
||||
}
|
||||
|
||||
func TestJoinDisplaynamesPermission(t *testing.T) {
|
||||
|
|
@ -3058,7 +3058,7 @@ func TestJoinRoomSwitchClient(t *testing.T) {
|
|||
|
||||
// Leave room.
|
||||
roomMsg = MustSucceed2(t, client2.JoinRoom, ctx, "")
|
||||
require.Equal("", roomMsg.Room.RoomId)
|
||||
require.Empty(roomMsg.Room.RoomId)
|
||||
}
|
||||
|
||||
func TestGetRealUserIP(t *testing.T) {
|
||||
|
|
|
|||
18
lru_test.go
18
lru_test.go
|
|
@ -41,7 +41,7 @@ func TestLruUnbound(t *testing.T) {
|
|||
for i := range count {
|
||||
key := strconv.Itoa(i)
|
||||
value := lru.Get(key)
|
||||
assert.EqualValues(i, value, "Failed for %s", key)
|
||||
assert.Equal(i, value, "Failed for %s", key)
|
||||
}
|
||||
// The first key ("0") is now the oldest.
|
||||
lru.RemoveOldest()
|
||||
|
|
@ -49,7 +49,7 @@ func TestLruUnbound(t *testing.T) {
|
|||
for i := range count {
|
||||
key := strconv.Itoa(i)
|
||||
value := lru.Get(key)
|
||||
assert.EqualValues(i, value, "Failed for %s", key)
|
||||
assert.Equal(i, value, "Failed for %s", key)
|
||||
}
|
||||
|
||||
// NOTE: Key "0" no longer exists below, so make sure to not set it again.
|
||||
|
|
@ -64,7 +64,7 @@ func TestLruUnbound(t *testing.T) {
|
|||
for i := count - 1; i >= 1; i-- {
|
||||
key := strconv.Itoa(i)
|
||||
value := lru.Get(key)
|
||||
assert.EqualValues(i, value, "Failed for %s", key)
|
||||
assert.Equal(i, value, "Failed for %s", key)
|
||||
}
|
||||
|
||||
// The last key ("9") is now the oldest.
|
||||
|
|
@ -74,9 +74,9 @@ func TestLruUnbound(t *testing.T) {
|
|||
key := strconv.Itoa(i)
|
||||
value := lru.Get(key)
|
||||
if i == 0 || i == count-1 {
|
||||
assert.EqualValues(0, value, "The value for key %s should have been removed", key)
|
||||
assert.Equal(0, value, "The value for key %s should have been removed", key)
|
||||
} else {
|
||||
assert.EqualValues(i, value, "Failed for %s", key)
|
||||
assert.Equal(i, value, "Failed for %s", key)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,9 +88,9 @@ func TestLruUnbound(t *testing.T) {
|
|||
key := strconv.Itoa(i)
|
||||
value := lru.Get(key)
|
||||
if i == 0 || i == count-1 || i == count/2 {
|
||||
assert.EqualValues(0, value, "The value for key %s should have been removed", key)
|
||||
assert.Equal(0, value, "The value for key %s should have been removed", key)
|
||||
} else {
|
||||
assert.EqualValues(i, value, "Failed for %s", key)
|
||||
assert.Equal(i, value, "Failed for %s", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -111,9 +111,9 @@ func TestLruBound(t *testing.T) {
|
|||
key := strconv.Itoa(i)
|
||||
value := lru.Get(key)
|
||||
if i < count-size {
|
||||
assert.EqualValues(0, value, "The value for key %s should have been removed", key)
|
||||
assert.Equal(0, value, "The value for key %s should have been removed", key)
|
||||
} else {
|
||||
assert.EqualValues(i, value, "Failed for %s", key)
|
||||
assert.Equal(i, value, "Failed for %s", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ type TestJanusEventsServerHandler struct {
|
|||
|
||||
func (h *TestJanusEventsServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
h.t.Helper()
|
||||
require := require.New(h.t)
|
||||
assert := assert.New(h.t)
|
||||
conn, err := h.upgrader.Upgrade(w, r, nil)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
|
||||
if conn.Subprotocol() == JanusEventsSubprotocol {
|
||||
addr := h.addr
|
||||
|
|
@ -70,10 +70,10 @@ func (h *TestJanusEventsServerHandler) ServeHTTP(w http.ResponseWriter, r *http.
|
|||
}
|
||||
|
||||
deadline := time.Now().Add(time.Second)
|
||||
require.NoError(conn.SetWriteDeadline(deadline))
|
||||
require.NoError(conn.WriteJSON(map[string]string{"error": "invalid_subprotocol"}))
|
||||
require.NoError(conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseProtocolError, "invalid_subprotocol"), deadline))
|
||||
require.NoError(conn.Close())
|
||||
assert.NoError(conn.SetWriteDeadline(deadline))
|
||||
assert.NoError(conn.WriteJSON(map[string]string{"error": "invalid_subprotocol"}))
|
||||
assert.NoError(conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseProtocolError, "invalid_subprotocol"), deadline))
|
||||
assert.NoError(conn.Close())
|
||||
}
|
||||
|
||||
func NewTestJanusEventsHandlerServer(t *testing.T) (*httptest.Server, string, *TestJanusEventsServerHandler) {
|
||||
|
|
@ -121,7 +121,7 @@ func TestJanusEventsHandlerNoMcu(t *testing.T) {
|
|||
if mt, msg, err := conn.ReadMessage(); err == nil {
|
||||
assert.Fail("connection was not closed", "expected close error, got message %s with type %d", string(msg), mt)
|
||||
} else if assert.ErrorAs(err, &ce) {
|
||||
assert.EqualValues(websocket.CloseInternalServerErr, ce.Code)
|
||||
assert.Equal(websocket.CloseInternalServerErr, ce.Code)
|
||||
assert.Equal("no mcu configured", ce.Text)
|
||||
}
|
||||
}
|
||||
|
|
@ -153,7 +153,7 @@ func TestJanusEventsHandlerInvalidMcu(t *testing.T) {
|
|||
if mt, msg, err := conn.ReadMessage(); err == nil {
|
||||
assert.Fail("connection was not closed", "expected close error, got message %s with type %d", string(msg), mt)
|
||||
} else if assert.ErrorAs(err, &ce) {
|
||||
assert.EqualValues(websocket.CloseInternalServerErr, ce.Code)
|
||||
assert.Equal(websocket.CloseInternalServerErr, ce.Code)
|
||||
assert.Equal("mcu does not support events", ce.Text)
|
||||
}
|
||||
}
|
||||
|
|
@ -186,7 +186,7 @@ func TestJanusEventsHandlerPublicIP(t *testing.T) {
|
|||
if mt, msg, err := conn.ReadMessage(); err == nil {
|
||||
assert.Fail("connection was not closed", "expected close error, got message %s with type %d", string(msg), mt)
|
||||
} else if assert.ErrorAs(err, &ce) {
|
||||
assert.EqualValues(websocket.ClosePolicyViolation, ce.Code)
|
||||
assert.Equal(websocket.ClosePolicyViolation, ce.Code)
|
||||
assert.Equal("only loopback and private connections allowed", ce.Text)
|
||||
}
|
||||
}
|
||||
|
|
@ -210,14 +210,14 @@ func (m *TestMcuWithEvents) UpdateBandwidth(handle uint64, media string, sent ap
|
|||
switch m.idx {
|
||||
case 1:
|
||||
assert.EqualValues(1, handle)
|
||||
assert.EqualValues("audio", media)
|
||||
assert.EqualValues(api.BandwidthFromBytes(100), sent)
|
||||
assert.EqualValues(api.BandwidthFromBytes(200), received)
|
||||
assert.Equal("audio", media)
|
||||
assert.Equal(api.BandwidthFromBytes(100), sent)
|
||||
assert.Equal(api.BandwidthFromBytes(200), received)
|
||||
case 2:
|
||||
assert.EqualValues(1, handle)
|
||||
assert.EqualValues("video", media)
|
||||
assert.EqualValues(api.BandwidthFromBytes(200), sent)
|
||||
assert.EqualValues(api.BandwidthFromBytes(300), received)
|
||||
assert.Equal("video", media)
|
||||
assert.Equal(api.BandwidthFromBytes(200), sent)
|
||||
assert.Equal(api.BandwidthFromBytes(300), received)
|
||||
default:
|
||||
assert.Fail("too many updates", "received update %d (handle=%d, media=%s, sent=%d, received=%d)", m.idx, handle, media, sent, received)
|
||||
}
|
||||
|
|
@ -638,6 +638,6 @@ func TestValueCounter(t *testing.T) {
|
|||
assert.EqualValues(1, c.Update("foo", 11))
|
||||
assert.EqualValues(10, c.Update("bar", 10))
|
||||
assert.EqualValues(1, c.Update("bar", 11))
|
||||
assert.EqualValues(uint64(math.MaxUint64-10), c.Update("baz", math.MaxUint64-10))
|
||||
assert.Equal(uint64(math.MaxUint64-10), c.Update("baz", math.MaxUint64-10))
|
||||
assert.EqualValues(20, c.Update("baz", 10))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,10 +122,10 @@ func TestJanusPublisherRemote(t *testing.T) {
|
|||
assert.Equal(hostname, value)
|
||||
}
|
||||
if value, found := api.GetStringMapEntry[float64](body, "port"); assert.True(found) {
|
||||
assert.EqualValues(port, value)
|
||||
assert.InEpsilon(port, value, 0.0001)
|
||||
}
|
||||
if value, found := api.GetStringMapEntry[float64](body, "rtcp_port"); assert.True(found) {
|
||||
assert.EqualValues(rtcpPort, value)
|
||||
assert.InEpsilon(rtcpPort, value, 0.0001)
|
||||
}
|
||||
if value, found := api.GetStringMapString[string](body, "remote_id"); assert.True(found) {
|
||||
prev := remotePublishId.Swap(value)
|
||||
|
|
|
|||
|
|
@ -104,11 +104,11 @@ func NewTestJanusGateway(t *testing.T) *TestJanusGateway {
|
|||
assert := assert.New(t)
|
||||
gateway.mu.Lock()
|
||||
defer gateway.mu.Unlock()
|
||||
assert.Len(gateway.sessions, 0)
|
||||
assert.Len(gateway.transactions, 0)
|
||||
assert.Len(gateway.handles, 0)
|
||||
assert.Len(gateway.rooms, 0)
|
||||
assert.Len(gateway.handleRooms, 0)
|
||||
assert.Empty(gateway.sessions)
|
||||
assert.Empty(gateway.transactions)
|
||||
assert.Empty(gateway.handles)
|
||||
assert.Empty(gateway.rooms)
|
||||
assert.Empty(gateway.handleRooms)
|
||||
})
|
||||
|
||||
return gateway
|
||||
|
|
@ -352,7 +352,7 @@ func (g *TestJanusGateway) processMessage(session *JanusSession, handle *TestJan
|
|||
}
|
||||
}
|
||||
|
||||
assert.EqualValues(g.t, room.id, uint64(rid))
|
||||
assert.Equal(g.t, room.id, uint64(rid))
|
||||
delete(g.rooms, uint64(rid))
|
||||
for h, r := range g.handleRooms {
|
||||
if r.id == room.id {
|
||||
|
|
@ -980,7 +980,7 @@ func Test_JanusPublisherGetStreamsAudioOnly(t *testing.T) {
|
|||
stream := streams[0]
|
||||
assert.Equal("audio", stream.Type)
|
||||
assert.Equal("audio", stream.Mid)
|
||||
assert.EqualValues(0, stream.Mindex)
|
||||
assert.Equal(0, stream.Mindex)
|
||||
assert.False(stream.Disabled)
|
||||
assert.Equal("opus", stream.Codec)
|
||||
assert.False(stream.Stereo)
|
||||
|
|
@ -1062,7 +1062,7 @@ func Test_JanusPublisherGetStreamsAudioVideo(t *testing.T) {
|
|||
stream := streams[0]
|
||||
assert.Equal("audio", stream.Type)
|
||||
assert.Equal("audio", stream.Mid)
|
||||
assert.EqualValues(0, stream.Mindex)
|
||||
assert.Equal(0, stream.Mindex)
|
||||
assert.False(stream.Disabled)
|
||||
assert.Equal("opus", stream.Codec)
|
||||
assert.False(stream.Stereo)
|
||||
|
|
@ -1072,7 +1072,7 @@ func Test_JanusPublisherGetStreamsAudioVideo(t *testing.T) {
|
|||
stream = streams[1]
|
||||
assert.Equal("video", stream.Type)
|
||||
assert.Equal("video", stream.Mid)
|
||||
assert.EqualValues(1, stream.Mindex)
|
||||
assert.Equal(1, stream.Mindex)
|
||||
assert.False(stream.Disabled)
|
||||
assert.Equal("H264", stream.Codec)
|
||||
assert.Equal("4d0028", stream.ProfileH264)
|
||||
|
|
@ -1121,12 +1121,12 @@ func Test_JanusPublisherSubscriber(t *testing.T) { // nolint:paralleltest
|
|||
assert.Nil(janusPub.Bandwidth())
|
||||
mcu.UpdateBandwidth(janusPub.Handle(), "video", api.BandwidthFromBytes(1000), api.BandwidthFromBytes(2000))
|
||||
if bw := janusPub.Bandwidth(); assert.NotNil(bw) {
|
||||
assert.EqualValues(api.BandwidthFromBytes(1000), bw.Sent)
|
||||
assert.EqualValues(api.BandwidthFromBytes(2000), bw.Received)
|
||||
assert.Equal(api.BandwidthFromBytes(1000), bw.Sent)
|
||||
assert.Equal(api.BandwidthFromBytes(2000), bw.Received)
|
||||
}
|
||||
if bw := mcu.Bandwidth(); assert.NotNil(bw) {
|
||||
assert.EqualValues(api.BandwidthFromBytes(1000), bw.Sent)
|
||||
assert.EqualValues(api.BandwidthFromBytes(2000), bw.Received)
|
||||
assert.Equal(api.BandwidthFromBytes(1000), bw.Sent)
|
||||
assert.Equal(api.BandwidthFromBytes(2000), bw.Received)
|
||||
}
|
||||
mcu.updateBandwidthStats()
|
||||
checkStatsValue(t, statsJanusBandwidthCurrent.WithLabelValues("incoming"), 2000)
|
||||
|
|
@ -1149,12 +1149,12 @@ func Test_JanusPublisherSubscriber(t *testing.T) { // nolint:paralleltest
|
|||
assert.Nil(janusSub.Bandwidth())
|
||||
mcu.UpdateBandwidth(janusSub.Handle(), "video", api.BandwidthFromBytes(3000), api.BandwidthFromBytes(4000))
|
||||
if bw := janusSub.Bandwidth(); assert.NotNil(bw) {
|
||||
assert.EqualValues(api.BandwidthFromBytes(3000), bw.Sent)
|
||||
assert.EqualValues(api.BandwidthFromBytes(4000), bw.Received)
|
||||
assert.Equal(api.BandwidthFromBytes(3000), bw.Sent)
|
||||
assert.Equal(api.BandwidthFromBytes(4000), bw.Received)
|
||||
}
|
||||
if bw := mcu.Bandwidth(); assert.NotNil(bw) {
|
||||
assert.EqualValues(api.BandwidthFromBytes(4000), bw.Sent)
|
||||
assert.EqualValues(api.BandwidthFromBytes(6000), bw.Received)
|
||||
assert.Equal(api.BandwidthFromBytes(4000), bw.Sent)
|
||||
assert.Equal(api.BandwidthFromBytes(6000), bw.Received)
|
||||
}
|
||||
checkStatsValue(t, statsJanusBandwidthCurrent.WithLabelValues("incoming"), 2000)
|
||||
checkStatsValue(t, statsJanusBandwidthCurrent.WithLabelValues("outgoing"), 1000)
|
||||
|
|
@ -1166,6 +1166,7 @@ func Test_JanusPublisherSubscriber(t *testing.T) { // nolint:paralleltest
|
|||
func Test_JanusSubscriberPublisher(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
|
||||
mcu, gateway := newMcuJanusForTesting(t)
|
||||
gateway.registerHandlers(map[string]TestJanusHandler{})
|
||||
|
|
@ -1190,7 +1191,10 @@ func Test_JanusSubscriberPublisher(t *testing.T) {
|
|||
defer close(done)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
pub, err := mcu.NewPublisher(ctx, listener1, pubId, "sid", StreamTypeVideo, settings1, initiator1)
|
||||
require.NoError(err)
|
||||
if !assert.NoError(err) {
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
<-ready
|
||||
pub.Close(context.Background())
|
||||
|
|
@ -1271,7 +1275,9 @@ func Test_JanusSubscriberRequestOffer(t *testing.T) {
|
|||
"sdp": MockSdpOfferAudioAndVideo,
|
||||
},
|
||||
}
|
||||
require.NoError(data.CheckValid())
|
||||
if !assert.NoError(data.CheckValid()) {
|
||||
return
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
pub.SendMessage(ctx, &MessageClientMessage{}, data, func(err error, m api.StringMap) {
|
||||
|
|
|
|||
|
|
@ -318,9 +318,9 @@ func (c *testProxyServerClient) processCommandMessage(msg *ProxyClientMessage) (
|
|||
|
||||
if assert.NotNil(c.t, msg.Command.PublisherSettings) {
|
||||
if assert.NotEqualValues(c.t, 0, msg.Command.PublisherSettings.Bitrate) {
|
||||
assert.EqualValues(c.t, msg.Command.Bitrate, msg.Command.PublisherSettings.Bitrate)
|
||||
assert.Equal(c.t, msg.Command.Bitrate, msg.Command.PublisherSettings.Bitrate)
|
||||
}
|
||||
assert.EqualValues(c.t, msg.Command.MediaTypes, msg.Command.PublisherSettings.MediaTypes)
|
||||
assert.Equal(c.t, msg.Command.MediaTypes, msg.Command.PublisherSettings.MediaTypes)
|
||||
if strings.Contains(c.t.Name(), "Codecs") {
|
||||
assert.Equal(c.t, "opus,g722", msg.Command.PublisherSettings.AudioCodec)
|
||||
assert.Equal(c.t, "vp9,vp8,av1", msg.Command.PublisherSettings.VideoCodec)
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ func testNatsClient_Subscribe(t *testing.T, client NatsClient) {
|
|||
}
|
||||
<-ch
|
||||
|
||||
require.EqualValues(maxPublish, received.Load(), "Received wrong # of messages")
|
||||
require.Equal(maxPublish, received.Load(), "Received wrong # of messages")
|
||||
}
|
||||
|
||||
func TestNatsClient_Subscribe(t *testing.T) { // nolint:paralleltest
|
||||
|
|
|
|||
|
|
@ -537,10 +537,10 @@ func TestProxyPublisherBandwidth(t *testing.T) {
|
|||
assert.EqualValues(1, message.Event.Load)
|
||||
if bw := message.Event.Bandwidth; assert.NotNil(bw) {
|
||||
if assert.NotNil(bw.Incoming) {
|
||||
assert.EqualValues(20, *bw.Incoming)
|
||||
assert.InEpsilon(20, *bw.Incoming, 0.0001)
|
||||
}
|
||||
if assert.NotNil(bw.Outgoing) {
|
||||
assert.EqualValues(10, *bw.Outgoing)
|
||||
assert.InEpsilon(10, *bw.Outgoing, 0.0001)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -893,7 +893,7 @@ func (p *TestRemotePublisher) MaxBitrate() api.Bandwidth {
|
|||
}
|
||||
|
||||
func (p *TestRemotePublisher) Close(ctx context.Context) {
|
||||
if count := p.refcnt.Add(-1); assert.True(p.t, count >= 0) && count == 0 {
|
||||
if count := p.refcnt.Add(-1); assert.GreaterOrEqual(p.t, int(count), 0) && count == 0 {
|
||||
p.closeFunc()
|
||||
shortCtx, cancel := context.WithTimeout(ctx, time.Millisecond)
|
||||
defer cancel()
|
||||
|
|
@ -1244,8 +1244,8 @@ func (p *UnpublishRemoteTestPublisher) UnpublishRemote(ctx context.Context, remo
|
|||
assert.Equal(p.t, remoteId, p.remoteId)
|
||||
if remoteData := p.remoteData; assert.NotNil(p.t, remoteData) &&
|
||||
assert.Equal(p.t, remoteData.hostname, hostname) &&
|
||||
assert.EqualValues(p.t, remoteData.port, port) &&
|
||||
assert.EqualValues(p.t, remoteData.rtcpPort, rtcpPort) {
|
||||
assert.Equal(p.t, remoteData.port, port) &&
|
||||
assert.Equal(p.t, remoteData.rtcpPort, rtcpPort) {
|
||||
p.remoteId = ""
|
||||
p.remoteData = nil
|
||||
}
|
||||
|
|
@ -1338,8 +1338,8 @@ func TestProxyUnpublishRemote(t *testing.T) {
|
|||
assert.Equal(hello2.Hello.SessionId, publisher.getRemoteId())
|
||||
if remoteData := publisher.getRemoteData(); assert.NotNil(remoteData) {
|
||||
assert.Equal("remote-host", remoteData.hostname)
|
||||
assert.EqualValues(10001, remoteData.port)
|
||||
assert.EqualValues(10002, remoteData.rtcpPort)
|
||||
assert.Equal(10001, remoteData.port)
|
||||
assert.Equal(10002, remoteData.rtcpPort)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1455,8 +1455,8 @@ func TestProxyUnpublishRemotePublisherClosed(t *testing.T) {
|
|||
assert.Equal(hello2.Hello.SessionId, publisher.getRemoteId())
|
||||
if remoteData := publisher.getRemoteData(); assert.NotNil(remoteData) {
|
||||
assert.Equal("remote-host", remoteData.hostname)
|
||||
assert.EqualValues(10001, remoteData.port)
|
||||
assert.EqualValues(10002, remoteData.rtcpPort)
|
||||
assert.Equal(10001, remoteData.port)
|
||||
assert.Equal(10002, remoteData.rtcpPort)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1481,8 +1481,8 @@ func TestProxyUnpublishRemotePublisherClosed(t *testing.T) {
|
|||
assert.Equal(hello2.Hello.SessionId, publisher.getRemoteId())
|
||||
if remoteData := publisher.getRemoteData(); assert.NotNil(remoteData) {
|
||||
assert.Equal("remote-host", remoteData.hostname)
|
||||
assert.EqualValues(10001, remoteData.port)
|
||||
assert.EqualValues(10002, remoteData.rtcpPort)
|
||||
assert.Equal(10001, remoteData.port)
|
||||
assert.Equal(10002, remoteData.rtcpPort)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1587,8 +1587,8 @@ func TestProxyUnpublishRemoteOnSessionClose(t *testing.T) {
|
|||
assert.Equal(hello2.Hello.SessionId, publisher.getRemoteId())
|
||||
if remoteData := publisher.getRemoteData(); assert.NotNil(remoteData) {
|
||||
assert.Equal("remote-host", remoteData.hostname)
|
||||
assert.EqualValues(10001, remoteData.port)
|
||||
assert.EqualValues(10002, remoteData.rtcpPort)
|
||||
assert.Equal(10001, remoteData.port)
|
||||
assert.Equal(10002, remoteData.rtcpPort)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ func TestRoom_InCall(t *testing.T) {
|
|||
} else {
|
||||
assert.False(t, ok, "%+v should not be valid", test.Value)
|
||||
}
|
||||
assert.EqualValues(t, test.InCall, inCall, "conversion failed for %+v", test.Value)
|
||||
assert.Equal(t, test.InCall, inCall, "conversion failed for %+v", test.Value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func assertCollectorChangeBy(t *testing.T, collector prometheus.Collector, delta
|
|||
t.Helper()
|
||||
|
||||
after := testutil.ToFloat64(collector)
|
||||
assert.EqualValues(t, delta, after-before, "failed for %s", desc)
|
||||
assert.InEpsilon(t, delta, after-before, 0.0001, "failed for %s", desc)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ func checkStatsValue(t *testing.T, collector prometheus.Collector, value float64
|
|||
pc := make([]uintptr, 10)
|
||||
n := runtime.Callers(2, pc)
|
||||
if n == 0 {
|
||||
assert.EqualValues(value, v, "failed for %s", desc)
|
||||
assert.InEpsilon(value, v, 0.0001, "failed for %s", desc)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ func checkStatsValue(t *testing.T, collector prometheus.Collector, value float64
|
|||
break
|
||||
}
|
||||
}
|
||||
assert.EqualValues(value, v, "Unexpected value for %s at\n%s", desc, stack.String())
|
||||
assert.InEpsilon(value, v, 0.0001, "Unexpected value for %s at\n%s", desc, stack.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1110,7 +1110,7 @@ func checkMessageTransientInitial(t *testing.T, message *ServerMessage, data api
|
|||
assert := assert.New(t)
|
||||
return checkMessageType(t, message, "transient") &&
|
||||
assert.Equal("initial", message.TransientData.Type, "invalid message type in %+v", message) &&
|
||||
assert.EqualValues(data, message.TransientData.Data, "invalid initial data in %+v", message)
|
||||
assert.Equal(data, message.TransientData.Data, "invalid initial data in %+v", message)
|
||||
}
|
||||
|
||||
func checkMessageInCallAll(t *testing.T, message *ServerMessage, roomId string, inCall int) bool {
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ func TestVirtualSession(t *testing.T) {
|
|||
if flagsMsg, ok := checkMessageParticipantFlags(t, msg4); ok {
|
||||
assert.Equal(roomId, flagsMsg.RoomId)
|
||||
assert.Equal(sessionId, flagsMsg.SessionId)
|
||||
assert.EqualValues(newFlags, flagsMsg.Flags)
|
||||
assert.Equal(newFlags, flagsMsg.Flags)
|
||||
}
|
||||
|
||||
// A new client will receive the initial flags of the virtual session.
|
||||
|
|
@ -162,7 +162,7 @@ func TestVirtualSession(t *testing.T) {
|
|||
|
||||
if assert.Equal(roomId, msg.Event.Flags.RoomId) &&
|
||||
assert.Equal(sessionId, msg.Event.Flags.SessionId) &&
|
||||
assert.EqualValues(newFlags, msg.Event.Flags.Flags) {
|
||||
assert.Equal(newFlags, msg.Event.Flags.Flags) {
|
||||
gotFlags = true
|
||||
break
|
||||
}
|
||||
|
|
@ -322,7 +322,7 @@ func TestVirtualSessionActorInformation(t *testing.T) {
|
|||
if flagsMsg, ok := checkMessageParticipantFlags(t, msg4); ok {
|
||||
assert.Equal(roomId, flagsMsg.RoomId)
|
||||
assert.Equal(sessionId, flagsMsg.SessionId)
|
||||
assert.EqualValues(newFlags, flagsMsg.Flags)
|
||||
assert.Equal(newFlags, flagsMsg.Flags)
|
||||
}
|
||||
|
||||
// A new client will receive the initial flags of the virtual session.
|
||||
|
|
@ -349,7 +349,7 @@ func TestVirtualSessionActorInformation(t *testing.T) {
|
|||
|
||||
if assert.Equal(roomId, msg.Event.Flags.RoomId) &&
|
||||
assert.Equal(sessionId, msg.Event.Flags.SessionId) &&
|
||||
assert.EqualValues(newFlags, msg.Event.Flags.Flags) {
|
||||
assert.Equal(newFlags, msg.Event.Flags.Flags) {
|
||||
gotFlags = true
|
||||
break
|
||||
}
|
||||
|
|
@ -414,7 +414,7 @@ func checkHasEntryWithInCall(t *testing.T, message *RoomEventServerMessage, sess
|
|||
}
|
||||
|
||||
if value, found := api.GetStringMapEntry[float64](entry, "inCall"); !assert.True(found, "inCall not found or invalid in %+v", entry) ||
|
||||
!assert.EqualValues(value, inCall, "invalid inCall") {
|
||||
!assert.InDelta(value, inCall, 0.0001, "invalid inCall") {
|
||||
return false
|
||||
}
|
||||
found = true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue