tlogger_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. *
  3. * Copyright 2020 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 grpctest
  19. import (
  20. "testing"
  21. "google.golang.org/grpc/grpclog"
  22. grpclogi "google.golang.org/grpc/internal/grpclog"
  23. )
  24. type s struct {
  25. Tester
  26. }
  27. func Test(t *testing.T) {
  28. RunSubTests(t, s{})
  29. }
  30. func (s) TestInfo(t *testing.T) {
  31. grpclog.Info("Info", "message.")
  32. }
  33. func (s) TestInfoln(t *testing.T) {
  34. grpclog.Infoln("Info", "message.")
  35. }
  36. func (s) TestInfof(t *testing.T) {
  37. grpclog.Infof("%v %v.", "Info", "message")
  38. }
  39. func (s) TestInfoDepth(t *testing.T) {
  40. grpclogi.InfoDepth(0, "Info", "depth", "message.")
  41. }
  42. func (s) TestWarning(t *testing.T) {
  43. grpclog.Warning("Warning", "message.")
  44. }
  45. func (s) TestWarningln(t *testing.T) {
  46. grpclog.Warningln("Warning", "message.")
  47. }
  48. func (s) TestWarningf(t *testing.T) {
  49. grpclog.Warningf("%v %v.", "Warning", "message")
  50. }
  51. func (s) TestWarningDepth(t *testing.T) {
  52. grpclogi.WarningDepth(0, "Warning", "depth", "message.")
  53. }
  54. func (s) TestError(t *testing.T) {
  55. const numErrors = 10
  56. TLogger.ExpectError("Expected error")
  57. TLogger.ExpectError("Expected ln error")
  58. TLogger.ExpectError("Expected formatted error")
  59. TLogger.ExpectErrorN("Expected repeated error", numErrors)
  60. grpclog.Error("Expected", "error")
  61. grpclog.Errorln("Expected", "ln", "error")
  62. grpclog.Errorf("%v %v %v", "Expected", "formatted", "error")
  63. for i := 0; i < numErrors; i++ {
  64. grpclog.Error("Expected repeated error")
  65. }
  66. }