Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-test-for-group
Browse files Browse the repository at this point in the history
  • Loading branch information
ei-sugimoto committed Dec 8, 2024
2 parents 368bbc3 + b1b084e commit 7a92ed6
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions internal/message/frame_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package message_test

import (
"bytes"
"testing"

"github.com/OkutaniDaichi0106/gomoqt/internal/message"
"github.com/stretchr/testify/assert"
)

func TestFrameMessage(t *testing.T) {
tests := map[string]struct {
payload []byte
want []byte
wantErr bool
}{
"valid payload": {payload: []byte{1, 2}, want: []byte{1, 2}, wantErr: false},
"empty payload": {payload: []byte{}, want: []byte{}, wantErr: false},
"string payload": {payload: []byte{0x62, 0x61, 0x72}, want: []byte{0x62, 0x61, 0x72}, wantErr: false},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()
frame := &message.FrameMessage{
Payload: tc.payload,
}
var buf bytes.Buffer

err := frame.Encode(&buf)
if err != nil && !tc.wantErr {
t.Fatalf("unexpected error: %v", err)
} else if err == nil && tc.wantErr {
t.Fatalf("expected error: %v", err)
}

err = frame.Decode(&buf)
if err != nil && !tc.wantErr {
t.Fatalf("unexpected error: %v", err)
} else if err == nil && tc.wantErr {
t.Fatalf("expected error: %v", err)
}

assert.Equal(t, frame.Payload, tc.payload)

})
}
}

0 comments on commit 7a92ed6

Please sign in to comment.