(t *testing.T)
| 20 | } |
| 21 | |
| 22 | func TestParseWebRTCMessage(t *testing.T) { |
| 23 | tests := []struct { |
| 24 | name string |
| 25 | message string |
| 26 | msg *WebRTCSignalMessage |
| 27 | checkPayload bool |
| 28 | wantErr bool |
| 29 | }{ |
| 30 | { |
| 31 | name: "non-utf8 encoded messages", |
| 32 | message: string([]byte{0x00}), |
| 33 | msg: nil, |
| 34 | checkPayload: false, |
| 35 | wantErr: true, |
| 36 | }, |
| 37 | { |
| 38 | name: "utf8 encoded messages", |
| 39 | message: msgs[0], |
| 40 | msg: &WebRTCSignalMessage{ |
| 41 | Type: "ANSWER", |
| 42 | Src: "dest-peer-id", |
| 43 | Dst: "someid", |
| 44 | }, |
| 45 | checkPayload: false, |
| 46 | wantErr: false, |
| 47 | }, |
| 48 | { |
| 49 | name: "invalid message", |
| 50 | message: "naberpamps", |
| 51 | msg: nil, |
| 52 | checkPayload: false, |
| 53 | wantErr: true, |
| 54 | }, |
| 55 | { |
| 56 | name: "parse answer message", |
| 57 | message: msgs[0], |
| 58 | msg: &WebRTCSignalMessage{ |
| 59 | Type: "ANSWER", |
| 60 | Src: "dest-peer-id", |
| 61 | Dst: "someid", |
| 62 | }, |
| 63 | checkPayload: false, |
| 64 | wantErr: false, |
| 65 | }, |
| 66 | } |
| 67 | |
| 68 | for _, tt := range tests { |
| 69 | t.Run(tt.name, func(t *testing.T) { |
| 70 | sm, err := ParseWebRTCSignalMessage(tt.message) |
| 71 | if (err != nil) != tt.wantErr { |
| 72 | t.Errorf("ParseWebRTCMessage() error = %v, wantErr %v", err, tt.wantErr) |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | // in case they are both nil |
| 77 | if sm == tt.msg { |
| 78 | return |
| 79 | } |
nothing calls this directly
no test coverage detected