Skip to content

Commit

Permalink
Merge a3c4236 into b1f0d19
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovic committed Apr 24, 2020
2 parents b1f0d19 + a3c4236 commit bd64d53
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 38 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
@@ -1,8 +1,7 @@
language: go
sudo: false
go:
- 1.14.x
- 1.13.x
- 1.12.x
env:
- GO111MODULE=off
go_import_path: github.com/nats-io/nats.go
Expand All @@ -21,4 +20,4 @@ before_script:
script:
- go test -i -race ./...
- go test -v -run=TestNoRace -p=1 ./...
- if [[ "$TRAVIS_GO_VERSION" =~ 1.13 ]]; then ./scripts/cov.sh TRAVIS; else go test -race -v -p=1 ./... --failfast; fi
- if [[ "$TRAVIS_GO_VERSION" =~ 1.14 ]]; then ./scripts/cov.sh TRAVIS; else go test -race -v -p=1 ./... --failfast; fi
4 changes: 2 additions & 2 deletions encoders/protobuf/protobuf_enc.go
@@ -1,4 +1,4 @@
// Copyright 2015-2018 The NATS Authors
// Copyright 2015-2020 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -16,8 +16,8 @@ package protobuf
import (
"errors"

"github.com/golang/protobuf/proto"
"github.com/nats-io/nats.go"
"google.golang.org/protobuf/proto"
)

// Additional index for registered Encoders.
Expand Down
194 changes: 169 additions & 25 deletions encoders/protobuf/testdata/pbtest.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions test/protobuf_test.go
@@ -1,4 +1,4 @@
// Copyright 2015-2019 The NATS Authors
// Copyright 2015-2020 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -14,6 +14,7 @@
package test

import (
"errors"
"reflect"
"testing"
"time"
Expand All @@ -38,24 +39,30 @@ func TestEncProtoMarshalStruct(t *testing.T) {

ec := NewProtoEncodedConn(t)
defer ec.Close()
ch := make(chan bool)

me := &pb.Person{Name: "derek", Age: 22, Address: "140 New Montgomery St"}
me.Children = make(map[string]*pb.Person)

me.Children["sam"] = &pb.Person{Name: "sam", Age: 19, Address: "140 New Montgomery St"}
me.Children["meg"] = &pb.Person{Name: "meg", Age: 17, Address: "140 New Montgomery St"}

ch := make(chan error, 1)
ec.Subscribe("protobuf_test", func(p *pb.Person) {
if !reflect.DeepEqual(p, me) {
t.Fatal("Did not receive the correct protobuf response")
var err error
if !reflect.DeepEqual(p.ProtoReflect(), me.ProtoReflect()) {
err = errors.New("Did not receive the correct protobuf response")
}
ch <- true
ch <- err
})

ec.Publish("protobuf_test", me)
if e := Wait(ch); e != nil {
t.Fatal("Did not receive the message")
select {
case e := <-ch:
if e != nil {
t.Fatal(e.Error())
}
case <-time.After(time.Second):
t.Fatal("Failed to receive message")
}
}

Expand Down Expand Up @@ -83,7 +90,7 @@ func TestEncProtoNilRequest(t *testing.T) {
t.Error("Fail to send empty message via encoded proto connection")
}

if !reflect.DeepEqual(testPerson, resp) {
if !reflect.DeepEqual(testPerson.ProtoReflect(), resp.ProtoReflect()) {
t.Error("Fail to receive encoded response")
}
}
Expand Down

0 comments on commit bd64d53

Please sign in to comment.