config_test.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 trace
  15. import (
  16. "reflect"
  17. "testing"
  18. )
  19. func TestApplyConfig(t *testing.T) {
  20. testCfgs := []Config{
  21. {},
  22. {
  23. MaxAttributesPerSpan: 1,
  24. MaxAnnotationEventsPerSpan: 2,
  25. MaxMessageEventsPerSpan: 3,
  26. MaxLinksPerSpan: 4,
  27. },
  28. {
  29. MaxAttributesPerSpan: -1,
  30. MaxAnnotationEventsPerSpan: 3,
  31. MaxMessageEventsPerSpan: -3,
  32. MaxLinksPerSpan: 5,
  33. }}
  34. cfg := config.Load().(*Config)
  35. wantCfgs := []Config{
  36. {
  37. DefaultSampler: cfg.DefaultSampler,
  38. IDGenerator: cfg.IDGenerator,
  39. MaxAttributesPerSpan: DefaultMaxAttributesPerSpan,
  40. MaxAnnotationEventsPerSpan: DefaultMaxAnnotationEventsPerSpan,
  41. MaxMessageEventsPerSpan: DefaultMaxMessageEventsPerSpan,
  42. MaxLinksPerSpan: DefaultMaxLinksPerSpan,
  43. },
  44. {
  45. DefaultSampler: cfg.DefaultSampler,
  46. IDGenerator: cfg.IDGenerator,
  47. MaxAttributesPerSpan: 1,
  48. MaxAnnotationEventsPerSpan: 2,
  49. MaxMessageEventsPerSpan: 3,
  50. MaxLinksPerSpan: 4,
  51. },
  52. {
  53. DefaultSampler: cfg.DefaultSampler,
  54. IDGenerator: cfg.IDGenerator,
  55. MaxAttributesPerSpan: 1,
  56. MaxAnnotationEventsPerSpan: 3,
  57. MaxMessageEventsPerSpan: 3,
  58. MaxLinksPerSpan: 5,
  59. }}
  60. for i, newCfg := range testCfgs {
  61. ApplyConfig(newCfg)
  62. gotCfg := config.Load().(*Config)
  63. wantCfg := wantCfgs[i]
  64. if got, want := reflect.ValueOf(gotCfg.DefaultSampler).Pointer(), reflect.ValueOf(wantCfg.DefaultSampler).Pointer(); got != want {
  65. t.Fatalf("testId = %d config.DefaultSampler = %#v; want %#v", i, got, want)
  66. }
  67. if got, want := gotCfg.IDGenerator, wantCfg.IDGenerator; got != want {
  68. t.Fatalf("testId = %d config.IDGenerator = %#v; want %#v", i, got, want)
  69. }
  70. if got, want := gotCfg.MaxAttributesPerSpan, wantCfg.MaxAttributesPerSpan; got != want {
  71. t.Fatalf("testId = %d config.MaxAttributesPerSpan = %#v; want %#v", i, got, want)
  72. }
  73. if got, want := gotCfg.MaxLinksPerSpan, wantCfg.MaxLinksPerSpan; got != want {
  74. t.Fatalf("testId = %d config.MaxLinksPerSpan = %#v; want %#v", i, got, want)
  75. }
  76. if got, want := gotCfg.MaxAnnotationEventsPerSpan, wantCfg.MaxAnnotationEventsPerSpan; got != want {
  77. t.Fatalf("testId = %d config.MaxAnnotationEventsPerSpan = %#v; want %#v", i, got, want)
  78. }
  79. if got, want := gotCfg.MaxMessageEventsPerSpan, wantCfg.MaxMessageEventsPerSpan; got != want {
  80. t.Fatalf("testId = %d config.MaxMessageEventsPerSpan = %#v; want %#v", i, got, want)
  81. }
  82. }
  83. }