-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add initial unit tests for dedicated and protostream (#44)
- Loading branch information
Showing
3 changed files
with
112 additions
and
1 deletion.
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
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,85 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/googleforgames/space-agon/game/pb" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsMemoRecipient(t *testing.T) { | ||
|
||
tests := []struct { | ||
cid int64 | ||
memo *pb.Memo | ||
name string | ||
isPanic bool | ||
correctRecipient bool | ||
}{ | ||
{ | ||
cid: int64(1), | ||
memo: &pb.Memo{ | ||
Recipient: &pb.Memo_To{ | ||
To: int64(1), | ||
}, | ||
}, | ||
name: "correct Memo_to recipient", | ||
isPanic: false, | ||
correctRecipient: true, | ||
}, | ||
{ | ||
cid: int64(1), | ||
memo: &pb.Memo{ | ||
Recipient: &pb.Memo_To{ | ||
To: int64(2), | ||
}, | ||
}, | ||
name: "incorrect Memo_to recipient", | ||
isPanic: false, | ||
correctRecipient: false, | ||
}, | ||
{ | ||
cid: int64(2), | ||
memo: &pb.Memo{ | ||
Recipient: &pb.Memo_EveryoneBut{ | ||
EveryoneBut: int64(1), | ||
}, | ||
}, | ||
name: "correct Memo_EveryoneBut recipient", | ||
isPanic: false, | ||
correctRecipient: true, | ||
}, | ||
{ | ||
cid: int64(1), | ||
memo: &pb.Memo{ | ||
Recipient: &pb.Memo_EveryoneBut{ | ||
EveryoneBut: int64(1), | ||
}, | ||
}, | ||
name: "incorrect Memo_EveryoneBut recipient", | ||
isPanic: false, | ||
correctRecipient: false, | ||
}, | ||
{ | ||
cid: int64(12), | ||
memo: &pb.Memo{}, | ||
name: "unknown memo recipient", | ||
isPanic: true, | ||
correctRecipient: false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
if test.isPanic { | ||
assert.Panics(t, func() { | ||
isMemoRecipient(test.cid, test.memo) | ||
}) | ||
} else if test.correctRecipient { | ||
assert.True(t, isMemoRecipient(test.cid, test.memo)) | ||
} else { | ||
assert.False(t, isMemoRecipient(test.cid, test.memo)) | ||
} | ||
}) | ||
} | ||
} |
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,26 @@ | ||
package protostream | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestDecodeVarint(t *testing.T) { | ||
tests := []struct { | ||
input []byte | ||
expected uint64 | ||
length int | ||
name string | ||
}{ | ||
{[]byte{0x00}, 0, 1, "zero value"}, | ||
{[]byte{0x01}, 1, 1, "positive value"}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
result, length := DecodeVarint(test.input) | ||
if result != test.expected || length != test.length { | ||
t.Errorf("got result: %v, length: %v, expected result: %v, length: %v)", result, length, test.expected, test.length) | ||
} | ||
}) | ||
} | ||
} |