Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

89 rindas
2.3 KiB

  1. // Copyright 2018, OpenCensus Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package ochttp
  15. import (
  16. "reflect"
  17. "strings"
  18. "testing"
  19. "go.opencensus.io/stats"
  20. "go.opencensus.io/stats/view"
  21. "go.opencensus.io/tag"
  22. )
  23. func TestClientViews(t *testing.T) {
  24. for _, v := range []*view.View{
  25. ClientSentBytesDistribution,
  26. ClientReceivedBytesDistribution,
  27. ClientRoundtripLatencyDistribution,
  28. ClientCompletedCount,
  29. } {
  30. if v.Measure == nil {
  31. t.Fatalf("nil measure: %v", v)
  32. }
  33. if m := v.Measure.Name(); !strings.HasPrefix(m, "opencensus.io/http/client/") {
  34. t.Errorf("Unexpected measure name prefix: %v", v)
  35. }
  36. if v.Name == "" {
  37. t.Errorf("Empty name: %v", v)
  38. }
  39. if !strings.HasPrefix(v.Name, "opencensus.io/http/client/") {
  40. t.Errorf("Unexpected prefix: %s", v.Name)
  41. }
  42. if v.Description == "" {
  43. t.Errorf("Empty description: %s", v.Name)
  44. }
  45. if !reflect.DeepEqual(v.TagKeys, []tag.Key{KeyClientMethod, KeyClientStatus}) {
  46. t.Errorf("Unexpected tags for client view %s: %v", v.Name, v.TagKeys)
  47. }
  48. if strings.HasSuffix(v.Description, ".") {
  49. t.Errorf("View description should not end with a period: %s", v.Name)
  50. }
  51. }
  52. }
  53. func TestClientTagKeys(t *testing.T) {
  54. for _, k := range []tag.Key{
  55. KeyClientStatus,
  56. KeyClientMethod,
  57. KeyClientHost,
  58. KeyClientPath,
  59. } {
  60. if !strings.HasPrefix(k.Name(), "http_client_") {
  61. t.Errorf("Unexpected prefix: %s", k.Name())
  62. }
  63. }
  64. }
  65. func TestClientMeasures(t *testing.T) {
  66. for _, m := range []stats.Measure{
  67. ClientSentBytes,
  68. ClientReceivedBytes,
  69. ClientRoundtripLatency,
  70. } {
  71. if !strings.HasPrefix(m.Name(), "opencensus.io/http/client/") {
  72. t.Errorf("Unexpected prefix: %v", m)
  73. }
  74. if strings.HasSuffix(m.Description(), ".") {
  75. t.Errorf("View description should not end with a period: %s", m.Name())
  76. }
  77. if len(m.Unit()) == 0 {
  78. t.Errorf("No unit: %s", m.Name())
  79. }
  80. }
  81. }