diff --git a/runtime/handler_test.go b/runtime/handler_test.go index b0ad6e2c90d..a0ba5dc03df 100644 --- a/runtime/handler_test.go +++ b/runtime/handler_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "reflect" + "sort" "testing" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" @@ -416,7 +417,7 @@ func TestOutgoingTrailerMatcher(t *testing.T) { headers: http.Header{ "Transfer-Encoding": []string{"chunked"}, "Content-Type": []string{"application/json"}, - "Trailer": []string{"Grpc-Trailer-Foo", "Grpc-Trailer-Baz"}, + "Trailer": []string{"Grpc-Trailer-Baz", "Grpc-Trailer-Foo"}, }, trailer: http.Header{ "Grpc-Trailer-Foo": []string{"bar"}, @@ -483,6 +484,9 @@ func TestOutgoingTrailerMatcher(t *testing.T) { t.Fatalf("StatusCode %d want %d", w.StatusCode, http.StatusOK) } + // Sort to the trailer headers to ensure the test is deterministic + sort.Strings(w.Header["Trailer"]) + if !reflect.DeepEqual(w.Header, tc.headers) { t.Fatalf("Header %v want %v", w.Header, tc.headers) }