From e8538bdf3bc6e0b6704ed6d807b878d5715aaf39 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 22 Jan 2025 00:26:38 +0100 Subject: [PATCH] Add unit test for constantTimeCompare. --- group/group_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/group/group_test.go b/group/group_test.go index 11fb7a5..a92885c 100644 --- a/group/group_test.go +++ b/group/group_test.go @@ -11,6 +11,28 @@ import ( "github.com/pion/webrtc/v3" ) +func TestConstantTimeCompare(t *testing.T) { + tests := []struct { + a, b string + }{ + {"", ""}, + {"a", "a"}, + {"foo", "foo"}, + {"foo", "bar"}, + {"foo", "foo1"}, + {"foo1", "foo"}, + } + + for _, test := range tests { + e := constantTimeCompare(test.a, test.b) + if e != (test.a == test.b) { + t.Errorf("constantTimeCompare(%v, %v): got %v", + test.a, test.b, e, + ) + } + } +} + func TestGroup(t *testing.T) { groups.groups = nil Add("group", &Description{})