Skip to content
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

test: fix tests for headers and trailers #1500

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/services/echo_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ func (s *echoServerImpl) Chat(stream pb.Echo_ChatServer) error {
for {
req, err := stream.Recv()
if err == io.EOF {
// Echo headers and trailers when the stream ends
echoStreamingHeaders(stream)
echoStreamingTrailers(stream)
return nil
}
Expand All @@ -152,7 +154,6 @@ func (s *echoServerImpl) Chat(stream pb.Echo_ChatServer) error {
if s != nil {
return s
}
echoStreamingHeaders(stream)
stream.Send(&pb.EchoResponse{Content: req.GetContent()})
}
}
Expand Down
8 changes: 4 additions & 4 deletions server/services/echo_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (m *mockUnaryStream) SetHeader(md metadata.MD) error {
return nil
}
func (m *mockUnaryStream) verify(expectHeadersAndTrailers bool) {
if expectHeadersAndTrailers && !reflect.DeepEqual([]string{"show", "case"}, m.trail) && !reflect.DeepEqual([]string{"showcaseHeader, anotherHeader"}, m.head) {
if expectHeadersAndTrailers && (!reflect.DeepEqual([]string{"show", "case"}, m.trail) || !reflect.DeepEqual([]string{"showcaseHeader", "anotherHeader"}, m.head)) {
m.t.Errorf("Unary stream did not get all expected headers and trailers.\nGot these headers: %+v\nGot these trailers: %+v", m.head, m.trail)
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func (m *mockExpandStream) verify(expectHeadersAndTrailers bool) {
if len(m.exp) > 0 {
m.t.Errorf("Expand did not stream all expected values. %d expected values remaining.", len(m.exp))
}
if expectHeadersAndTrailers && !reflect.DeepEqual([]string{"show", "case"}, m.trail) && !reflect.DeepEqual([]string{"showcaseHeader", "anotherHeader"}, m.head) {
if expectHeadersAndTrailers && (!reflect.DeepEqual([]string{"show", "case"}, m.trail) || !reflect.DeepEqual([]string{"showcaseHeader", "anotherHeader"}, m.head)) {
m.t.Errorf("Expand did not get all expected headers and trailers.\nGot these headers: %+v\nGot these trailers: %+v", m.head, m.trail)
}
}
Expand Down Expand Up @@ -266,7 +266,7 @@ func (m *mockCollectStream) SetTrailer(md metadata.MD) {
}

func (m *mockCollectStream) verify(expectHeadersAndTrailers bool) {
if expectHeadersAndTrailers && !reflect.DeepEqual([]string{"show", "case"}, m.trail) && !reflect.DeepEqual([]string{"showcaseHeader", "anotherHeader"}, m.head) {
if expectHeadersAndTrailers && (!reflect.DeepEqual([]string{"show", "case"}, m.trail) || !reflect.DeepEqual([]string{"showcaseHeader", "anotherHeader"}, m.head)) {
m.t.Errorf("Collect did not get all expected trailers.\nGot these headers: %+v\nGot these trailers: %+v", m.head, m.trail)
}
}
Expand Down Expand Up @@ -367,7 +367,7 @@ func (m *mockChatStream) SetTrailer(md metadata.MD) {
}

func (m *mockChatStream) verify(expectHeadersAndTrailers bool) {
if expectHeadersAndTrailers && !reflect.DeepEqual([]string{"show", "case"}, m.trail) && !reflect.DeepEqual([]string{"showcaseHeader", "anotherHeader"}, m.head) {
if expectHeadersAndTrailers && (!reflect.DeepEqual([]string{"show", "case"}, m.trail) || !reflect.DeepEqual([]string{"showcaseHeader", "anotherHeader"}, m.head)) {
m.t.Errorf("Chat did not get all expected trailers.\nGot these headers: %+v\nGot these trailers: %+v", m.head, m.trail)
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/services/sequence_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (m *mockStreamSequence) verify(expectHeadersAndTrailers bool) {
if len(m.exp) > 0 {
m.t.Errorf("Expand did not stream all expected values. %d expected values remaining.", len(m.exp))
}
if expectHeadersAndTrailers && !reflect.DeepEqual([]string{"show", "case"}, m.trail) && !reflect.DeepEqual([]string{"showcaseHeader", "anotherHeader"}, m.head) {
if expectHeadersAndTrailers && (!reflect.DeepEqual([]string{"show", "case"}, m.trail) || !reflect.DeepEqual([]string{"showcaseHeader", "anotherHeader"}, m.head)) {
m.t.Errorf("Expand did not get all expected headers and trailers.\nGot these headers: %+v\nGot these trailers: %+v", m.head, m.trail)
}
}
Expand Down