-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature grpc version echo api #321
Closed
JayKaku
wants to merge
29
commits into
stefanprodan:master
from
JayKaku:feature-gRPC-version-echo-api
Closed
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
2bd6392
Testing with echo
JayKaku ed977d9
Merge branch 'master' of https://github.com/stefanprodan/podinfo
JayKaku 2f41d6c
Started the GRPC APIs with Version API
Prashant-Dwivedi-08-01 e03c890
Complete another set of APIs
Prashant-Dwivedi-08-01 e9fc595
Merge pull request #1 from JayKaku/dev_prash_grpc_api
Prashant-Dwivedi-08-01 c09d68a
test
JayKaku d4d1df7
grpc api partial
JayKaku 944fbf2
Updated the logger
Prashant-Dwivedi-08-01 78f7a69
delay n env grpc api added
JayKaku 61b5cdd
Merge branch 'master' of https://github.com/JayKaku/podinfo
Prashant-Dwivedi-08-01 d49f09a
Updated the status API
Prashant-Dwivedi-08-01 de13843
header api added
JayKaku 93ad600
updated header, info and echo
JayKaku f7efffb
info test, mockgrpcserver added
JayKaku 10eecb6
added tests for half of grpc apis
JayKaku eff0843
Added the test cases for GRPC apis
Prashant-Dwivedi-08-01 1742d0c
Merge pull request #2 from JayKaku/dev-prash-grpc-tests
JayKaku d366557
added more information for error status in grpc
JayKaku 721d0e4
Merge branch 'master' of https://github.com/JayKaku/podinfo
JayKaku 59f64f8
patched env test to "PATH" for linux users
JayKaku 282ec7d
package api to http, new folder structure [tested]
JayKaku 9bb9cfe
error handling for grpc/info
JayKaku 406ef7b
Merge branch 'stefanprodan:master' into master
JayKaku 1351240
cleaned up comments
JayKaku 6b68325
Merge branch 'master' of https://github.com/JayKaku/podinfo
JayKaku c6df291
verion and echo api
JayKaku 6408efa
restructured api to api/http, api/grpc, pkg http
JayKaku 35d3248
remoced tash
JayKaku 8011621
Merge branch 'feature/grpc-version-echo-apis' into feature-gRPC-versi…
JayKaku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,17 @@ | ||
package grpc | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/stefanprodan/podinfo/pkg/api/grpc/echo" | ||
) | ||
|
||
type echoServer struct { | ||
echo.UnimplementedEchoServiceServer | ||
} | ||
|
||
func (s *echoServer) Echo (ctx context.Context, message *echo.Message) (*echo.Message, error){ | ||
log.Printf("Received message body from client: %s", message.Body) | ||
return &echo.Message {Body: message.Body}, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,14 @@ | ||
syntax = "proto3"; | ||
|
||
option go_package = "./echo"; | ||
|
||
package echo; | ||
|
||
message Message { | ||
string body = 1; | ||
} | ||
|
||
|
||
service EchoService { | ||
rpc Echo(Message) returns (Message) {} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,69 @@ | ||
package grpc | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"net" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/stefanprodan/podinfo/pkg/api/grpc/echo" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/status" | ||
"google.golang.org/grpc/test/bufconn" | ||
) | ||
|
||
func TestGrpcEcho(t *testing.T) { | ||
|
||
// Server initialization | ||
// bufconn => uses in-memory connection instead of system network I/O | ||
lis := bufconn.Listen(1024*1024) | ||
t.Cleanup(func() { | ||
lis.Close() | ||
}) | ||
|
||
srv := grpc.NewServer() | ||
t.Cleanup(func() { | ||
srv.Stop() | ||
}) | ||
|
||
echo.RegisterEchoServiceServer(srv, &echoServer{}) | ||
|
||
go func(){ | ||
if err := srv.Serve(lis); err != nil { | ||
log.Fatalf("srv.Serve %v", err) | ||
} | ||
}() | ||
|
||
// - Test | ||
dialer := func(context.Context, string) (net.Conn, error){ | ||
return lis.Dial() | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
conn, err := grpc.DialContext(ctx, "", grpc.WithContextDialer(dialer), grpc.WithInsecure()) | ||
t.Cleanup(func() { | ||
conn.Close() | ||
}) | ||
|
||
if err != nil { | ||
t.Fatalf("grpc.DialContext %v", err) | ||
} | ||
|
||
client := echo.NewEchoServiceClient(conn) | ||
res , err := client.Echo(context.Background(), &echo.Message{Body:"test123-test"}) | ||
|
||
// Check the status code is what we expect. | ||
if _, ok := status.FromError(err); !ok { | ||
t.Errorf("Echo returned type %T, want %T", err, status.Error) | ||
} | ||
|
||
// Check the response body is what we expect. | ||
expected := ".*body.*test123-test.*" | ||
r := regexp.MustCompile(expected) | ||
if !r.MatchString(res.String()) { | ||
t.Fatalf("Returned unexpected body:\ngot \n%v \nwant \n%s", | ||
res, expected) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to use the server logger instead of default one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright