-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from OkutaniDaichi0106/feat/add-test-for-group
Feat/add test for group
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package message_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/OkutaniDaichi0106/gomoqt/internal/message" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGroupMessage(t *testing.T) { | ||
tests := map[string]struct { | ||
testcase message.GroupMessage | ||
want message.GroupMessage | ||
wantErr bool | ||
}{ | ||
"valid parameter": { | ||
testcase: message.GroupMessage{ | ||
SubscribeID: 1, | ||
GroupSequence: 1, | ||
PublisherPriority: 1, | ||
}, | ||
want: message.GroupMessage{ | ||
SubscribeID: 1, | ||
GroupSequence: 1, | ||
PublisherPriority: 1, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for name, tc := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
group := tc.testcase | ||
var buf bytes.Buffer | ||
err := group.Encode(&buf) | ||
if err != nil && !tc.wantErr { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
|
||
err = group.Decode(&buf) | ||
if err != nil && !tc.wantErr { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
|
||
if err == nil && tc.wantErr { | ||
t.Fatalf("expected error") | ||
} | ||
|
||
assert.Equal(t, group, tc.want) | ||
|
||
}) | ||
} | ||
} |