-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathrole_test.go
More file actions
63 lines (55 loc) · 1.4 KB
/
role_test.go
File metadata and controls
63 lines (55 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
//go:build !js
package ice
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestUnmarshalText_Success(t *testing.T) {
tests := []struct {
name string
in string
want Role
}{
{"controlling", "controlling", Controlling},
{"controlled", "controlled", Controlled},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var r Role
err := r.UnmarshalText([]byte(tt.in))
require.NoError(t, err)
require.Equal(t, tt.want, r)
})
}
}
func TestUnmarshalText_UnknownKeepsValueAndErrors(t *testing.T) {
r := Controlled
err := r.UnmarshalText([]byte("neither"))
require.ErrorIs(t, err, errUnknownRole)
require.Equal(t, Controlled, r, "role should remain unchanged on error")
}
func TestMarshalText(t *testing.T) {
tests := []struct {
name string
in Role
want string
}{
{"controlling", Controlling, "controlling"},
{"controlled", Controlled, "controlled"},
{"unknown", Role(99), "unknown"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b, err := tt.in.MarshalText()
require.NoError(t, err)
require.Equal(t, tt.want, string(b))
})
}
}
func TestString(t *testing.T) {
require.Equal(t, "controlling", Controlling.String())
require.Equal(t, "controlled", Controlled.String())
require.Equal(t, "unknown", Role(255).String())
}