File: icecandidateinit_test.go

package info (click to toggle)
golang-github-pion-webrtc.v3 3.1.56-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,392 kB
  • sloc: javascript: 595; sh: 28; makefile: 5
file content (52 lines) | stat: -rw-r--r-- 1,236 bytes parent folder | download | duplicates (2)
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
package webrtc

import (
	"encoding/json"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestICECandidateInit_Serialization(t *testing.T) {
	tt := []struct {
		candidate  ICECandidateInit
		serialized string
	}{
		{ICECandidateInit{
			Candidate:        "candidate:abc123",
			SDPMid:           refString("0"),
			SDPMLineIndex:    refUint16(0),
			UsernameFragment: refString("def"),
		}, `{"candidate":"candidate:abc123","sdpMid":"0","sdpMLineIndex":0,"usernameFragment":"def"}`},
		{ICECandidateInit{
			Candidate: "candidate:abc123",
		}, `{"candidate":"candidate:abc123","sdpMid":null,"sdpMLineIndex":null,"usernameFragment":null}`},
	}

	for i, tc := range tt {
		b, err := json.Marshal(tc.candidate)
		if err != nil {
			t.Errorf("Failed to marshal %d: %v", i, err)
		}
		actualSerialized := string(b)
		if actualSerialized != tc.serialized {
			t.Errorf("%d expected %s got %s", i, tc.serialized, actualSerialized)
		}

		var actual ICECandidateInit
		err = json.Unmarshal(b, &actual)
		if err != nil {
			t.Errorf("Failed to unmarshal %d: %v", i, err)
		}

		assert.Equal(t, tc.candidate, actual, "should match")
	}
}

func refString(s string) *string {
	return &s
}

func refUint16(i uint16) *uint16 {
	return &i
}