Skip to content

Commit

Permalink
fixes linkedin#87
Browse files Browse the repository at this point in the history
  • Loading branch information
Karrick S. McDermott committed Sep 13, 2017
1 parent 2431ab9 commit 7bf1da8
Show file tree
Hide file tree
Showing 23 changed files with 135 additions and 159 deletions.
2 changes: 1 addition & 1 deletion array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion benchmark_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"io/ioutil"
Expand Down
2 changes: 1 addition & 1 deletion benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import "testing"

Expand Down
20 changes: 9 additions & 11 deletions binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,34 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"bytes"
"fmt"
"math"
"testing"

"github.com/linkedin/goavro"
)

var morePositiveThanMaxBlockCount, morePositiveThanMaxBlockSize, moreNegativeThanMaxBlockCount, mostNegativeBlockCount []byte

func init() {
c, err := goavro.NewCodec("long")
c, err := NewCodec("long")
if err != nil {
panic(err)
}

morePositiveThanMaxBlockCount, err = c.BinaryFromNative(nil, (goavro.MaxBlockCount + 1))
morePositiveThanMaxBlockCount, err = c.BinaryFromNative(nil, (MaxBlockCount + 1))
if err != nil {
panic(err)
}

morePositiveThanMaxBlockSize, err = c.BinaryFromNative(nil, (goavro.MaxBlockSize + 1))
morePositiveThanMaxBlockSize, err = c.BinaryFromNative(nil, (MaxBlockSize + 1))
if err != nil {
panic(err)
}

moreNegativeThanMaxBlockCount, err = c.BinaryFromNative(nil, -(goavro.MaxBlockCount + 1))
moreNegativeThanMaxBlockCount, err = c.BinaryFromNative(nil, -(MaxBlockCount + 1))
if err != nil {
panic(err)
}
Expand All @@ -48,7 +46,7 @@ func init() {
}

func testBinaryDecodeFail(t *testing.T, schema string, buf []byte, errorMessage string) {
c, err := goavro.NewCodec(schema)
c, err := NewCodec(schema)
if err != nil {
t.Fatal(err)
}
Expand All @@ -63,7 +61,7 @@ func testBinaryDecodeFail(t *testing.T, schema string, buf []byte, errorMessage
}

func testBinaryEncodeFail(t *testing.T, schema string, datum interface{}, errorMessage string) {
c, err := goavro.NewCodec(schema)
c, err := NewCodec(schema)
if err != nil {
t.Fatal(err)
}
Expand All @@ -83,7 +81,7 @@ func testBinaryDecodeFailShortBuffer(t *testing.T, schema string, buf []byte) {
}

func testBinaryDecodePass(t *testing.T, schema string, datum interface{}, encoded []byte) {
codec, err := goavro.NewCodec(schema)
codec, err := NewCodec(schema)
if err != nil {
t.Fatal(err)
}
Expand All @@ -107,7 +105,7 @@ func testBinaryDecodePass(t *testing.T, schema string, datum interface{}, encode
}

func testBinaryEncodePass(t *testing.T, schema string, datum interface{}, expected []byte) {
codec, err := goavro.NewCodec(schema)
codec, err := NewCodec(schema)
if err != nil {
t.Fatalf("Schma: %q %s", schema, err)
}
Expand Down
2 changes: 1 addition & 1 deletion boolean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import "testing"

Expand Down
2 changes: 1 addition & 1 deletion bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion enum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"testing"
Expand Down
6 changes: 2 additions & 4 deletions fixed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"testing"

"github.com/linkedin/goavro"
)

func TestSchemaFixed(t *testing.T) {
Expand All @@ -39,7 +37,7 @@ func TestFixedDecodeBufferUnderflow(t *testing.T) {
}

func TestFixedDecodeWithExtra(t *testing.T) {
c, err := goavro.NewCodec(`{"type":"fixed","name":"foo","size":4}`)
c, err := NewCodec(`{"type":"fixed","name":"foo","size":4}`)
if err != nil {
t.Errorf("Actual: %#v; Expected: %#v", err, nil)
}
Expand Down
2 changes: 1 addition & 1 deletion floatingPoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"math"
Expand Down
2 changes: 1 addition & 1 deletion helperV1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"bytes"
Expand Down
20 changes: 9 additions & 11 deletions helperV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,23 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"bytes"
"testing"

v2 "github.com/linkedin/goavro"
)

func newCodecUsingV2(tb testing.TB, schema string) *v2.Codec {
codec, err := v2.NewCodec(schema)
func newCodecUsingV2(tb testing.TB, schema string) *Codec {
codec, err := NewCodec(schema)
if err != nil {
tb.Fatal(err)
}
return codec
}

func nativeFromAvroUsingV2(tb testing.TB, avroBlob []byte) ([]interface{}, *v2.Codec) {
ocf, err := v2.NewOCFReader(bytes.NewReader(avroBlob))
func nativeFromAvroUsingV2(tb testing.TB, avroBlob []byte) ([]interface{}, *Codec) {
ocf, err := NewOCFReader(bytes.NewReader(avroBlob))
if err != nil {
tb.Fatal(err)
}
Expand All @@ -44,7 +42,7 @@ func nativeFromAvroUsingV2(tb testing.TB, avroBlob []byte) ([]interface{}, *v2.C
return nativeData, ocf.Codec()
}

func binaryFromNativeUsingV2(tb testing.TB, codec *v2.Codec, nativeData []interface{}) [][]byte {
func binaryFromNativeUsingV2(tb testing.TB, codec *Codec, nativeData []interface{}) [][]byte {
binaryData := make([][]byte, len(nativeData))
for i, datum := range nativeData {
binaryDatum, err := codec.BinaryFromNative(nil, datum)
Expand All @@ -56,7 +54,7 @@ func binaryFromNativeUsingV2(tb testing.TB, codec *v2.Codec, nativeData []interf
return binaryData
}

func textFromNativeUsingV2(tb testing.TB, codec *v2.Codec, nativeData []interface{}) [][]byte {
func textFromNativeUsingV2(tb testing.TB, codec *Codec, nativeData []interface{}) [][]byte {
textData := make([][]byte, len(nativeData))
for i, nativeDatum := range nativeData {
textDatum, err := codec.TextualFromNative(nil, nativeDatum)
Expand All @@ -68,7 +66,7 @@ func textFromNativeUsingV2(tb testing.TB, codec *v2.Codec, nativeData []interfac
return textData
}

func nativeFromBinaryUsingV2(tb testing.TB, codec *v2.Codec, binaryData [][]byte) []interface{} {
func nativeFromBinaryUsingV2(tb testing.TB, codec *Codec, binaryData [][]byte) []interface{} {
nativeData := make([]interface{}, len(binaryData))
for i, binaryDatum := range binaryData {
nativeDatum, buf, err := codec.NativeFromBinary(binaryDatum)
Expand All @@ -83,7 +81,7 @@ func nativeFromBinaryUsingV2(tb testing.TB, codec *v2.Codec, binaryData [][]byte
return nativeData
}

func nativeFromTextUsingV2(tb testing.TB, codec *v2.Codec, textData [][]byte) []interface{} {
func nativeFromTextUsingV2(tb testing.TB, codec *Codec, textData [][]byte) []interface{} {
nativeData := make([]interface{}, len(textData))
for i, textDatum := range textData {
nativeDatum, buf, err := codec.NativeFromTextual(textDatum)
Expand Down
2 changes: 1 addition & 1 deletion helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"io"
Expand Down
2 changes: 1 addition & 1 deletion integer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"testing"
Expand Down
8 changes: 3 additions & 5 deletions map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"fmt"
"log"
"testing"

"github.com/linkedin/goavro"
)

func TestMapSchema(t *testing.T) {
Expand Down Expand Up @@ -56,7 +54,7 @@ func TestMapDecodeNextBlockCountCannotDecode(t *testing.T) {
}

func TestMapDecodeNextBlockCountNegative(t *testing.T) {
c, err := goavro.NewCodec(`{"type":"map","values":"int"}`)
c, err := NewCodec(`{"type":"map","values":"int"}`)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -152,7 +150,7 @@ func TestMapTextualReceiveSliceInt(t *testing.T) {
}

func ExampleMap() {
codec, err := goavro.NewCodec(`{
codec, err := NewCodec(`{
"name": "r1",
"type": "record",
"fields": [{
Expand Down
2 changes: 1 addition & 1 deletion null_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import "testing"

Expand Down
12 changes: 5 additions & 7 deletions ocf_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

package goavro_test
package goavro

import (
"bytes"
"testing"

"github.com/linkedin/goavro"
)

// readOCFHeader, magic bytes

func TestReadOCFHeaderMagicBytes(t *testing.T) {
_, err := goavro.NewOCFReader(bytes.NewBuffer([]byte("Obj"))) // missing fourth byte
_, err := NewOCFReader(bytes.NewBuffer([]byte("Obj"))) // missing fourth byte
ensureError(t, err, "cannot create OCF")

_, err = goavro.NewOCFReader(bytes.NewBuffer([]byte("....")))
_, err = NewOCFReader(bytes.NewBuffer([]byte("....")))
ensureError(t, err, "cannot create OCF")
}

Expand All @@ -31,7 +29,7 @@ func TestReadOCFHeaderMagicBytes(t *testing.T) {
//

func testCannotReadOCFHeader(t *testing.T, input []byte, expected ...string) {
_, err := goavro.NewOCFReader(bytes.NewBuffer(append([]byte("Obj\x01"), input...)))
_, err := NewOCFReader(bytes.NewBuffer(append([]byte("Obj\x01"), input...)))
ensureError(t, err, append([]string{"cannot read OCF header"}, expected...)...)
}

Expand Down Expand Up @@ -94,7 +92,7 @@ func TestReadOCFHeaderMetadataSyncMarker(t *testing.T) {
//

// func testOCFReader(t *testing.T, schema string, input []byte, expected ...string) {
// _, err := goavro.NewOCFReader(bytes.NewBuffer(append([]byte("Obj\x01"), input...)))
// _, err := NewOCFReader(bytes.NewBuffer(append([]byte("Obj\x01"), input...)))
// ensureError(t, err, append([]string{"any prefix?"}, expected...)...)
// }

Expand Down
Loading

0 comments on commit 7bf1da8

Please sign in to comment.