-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also added some simple tests to freeze the current behaviour of utils methods.
- Loading branch information
Vyacheslav Kulakov
committed
Dec 14, 2019
1 parent
5a8ad23
commit d61181e
Showing
6 changed files
with
107 additions
and
5 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,2 @@ | ||
# IDEs | ||
.idea |
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,9 @@ | ||
module github.com/myzhan/avroipc | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/golang/snappy v0.0.1 // indirect | ||
github.com/linkedin/goavro v2.1.0+incompatible | ||
github.com/stretchr/testify v1.4.0 | ||
) |
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,15 @@ | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= | ||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= | ||
github.com/linkedin/goavro v2.1.0+incompatible h1:DV2aUlj2xZiuxQyvag8Dy7zjY69ENjS66bWkSfdpddY= | ||
github.com/linkedin/goavro v2.1.0+incompatible/go.mod h1:bBCwI2eGYpUI/4820s67MElg9tdeLbINjLjiM2xZFYM= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= | ||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
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
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,78 @@ | ||
package avroipc | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_recvBytes(t *testing.T) { | ||
t.Run("zero value", func(t *testing.T) { | ||
buf := bytes.NewBuffer([]byte("test")) | ||
actual := recvBytes(buf, 2) | ||
expected := []byte{0x74, 0x65} | ||
|
||
require.Equal(t, expected, actual) | ||
}) | ||
|
||
t.Run("normal value", func(t *testing.T) { | ||
buf := bytes.NewBuffer([]byte("test")) | ||
actual := recvBytes(buf, 4) | ||
expected := []byte{0x74, 0x65, 0x73, 0x74} | ||
|
||
require.Equal(t, expected, actual) | ||
}) | ||
} | ||
|
||
func Test_encodeInt(t *testing.T) { | ||
t.Run("zero value", func(t *testing.T) { | ||
actual := encodeInt(0) | ||
expected := []byte{0x0} | ||
|
||
require.Equal(t, expected, actual) | ||
}) | ||
|
||
t.Run("normal value", func(t *testing.T) { | ||
actual := encodeInt(7) | ||
expected := []byte{0xe} | ||
|
||
require.Equal(t, expected, actual) | ||
}) | ||
} | ||
|
||
func Test_messageHeader(t *testing.T) { | ||
actual := messageHeader() | ||
expected := []byte{ | ||
// Meta header | ||
0x0, | ||
// Method name length | ||
0xc, | ||
// Method name: append | ||
0x61, 0x70, 0x70, 0x65, 0x6e, 0x64} | ||
|
||
require.Equal(t, expected, actual) | ||
} | ||
|
||
func Test_getMD5(t *testing.T) { | ||
t.Run("no values", func(t *testing.T) { | ||
actual := getMD5() | ||
expected := []byte{0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x0, 0xb2, 0x4, 0xe9, 0x80, 0x9, 0x98, 0xec, 0xf8, 0x42, 0x7e} | ||
|
||
require.Equal(t, expected, actual) | ||
}) | ||
|
||
t.Run("single value", func(t *testing.T) { | ||
actual := getMD5("test string") | ||
expected := []byte{0x6f, 0x8d, 0xb5, 0x99, 0xde, 0x98, 0x6f, 0xab, 0x7a, 0x21, 0x62, 0x5b, 0x79, 0x16, 0x58, 0x9c} | ||
|
||
require.Equal(t, expected, actual) | ||
}) | ||
|
||
t.Run("multiple values", func(t *testing.T) { | ||
actual := getMD5("string 1", "string 2") | ||
expected := []byte{0x60, 0x29, 0x64, 0x59, 0xb, 0x60, 0x61, 0x92, 0x57, 0x8c, 0xf3, 0x2b, 0xdb, 0x3a, 0xa8, 0x58} | ||
|
||
require.Equal(t, expected, actual) | ||
}) | ||
} |