util_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. *
  3. * Copyright 2018 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package binarylog
  19. import "testing"
  20. func TestParseMethodName(t *testing.T) {
  21. testCases := []struct {
  22. methodName string
  23. service, method string
  24. }{
  25. {methodName: "/s/m", service: "s", method: "m"},
  26. {methodName: "/p.s/m", service: "p.s", method: "m"},
  27. {methodName: "/p/s/m", service: "p/s", method: "m"},
  28. }
  29. for _, tc := range testCases {
  30. s, m, err := parseMethodName(tc.methodName)
  31. if err != nil {
  32. t.Errorf("Parsing %q got error %v, want nil", tc.methodName, err)
  33. continue
  34. }
  35. if s != tc.service || m != tc.method {
  36. t.Errorf("Parseing %q got service %q, method %q, want service %q, method %q",
  37. tc.methodName, s, m, tc.service, tc.method,
  38. )
  39. }
  40. }
  41. }
  42. func TestParseMethodNameInvalid(t *testing.T) {
  43. testCases := []string{
  44. "/",
  45. "/sm",
  46. "",
  47. "sm",
  48. }
  49. for _, tc := range testCases {
  50. _, _, err := parseMethodName(tc)
  51. if err == nil {
  52. t.Errorf("Parsing %q got nil error, want non-nil error", tc)
  53. }
  54. }
  55. }