util_test.go 405 B

123456789101112131415161718192021
  1. package trace
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestFromContext(t *testing.T) {
  8. report := &mockReport{}
  9. t1 := newTracer("service1", report, &Config{DisableSample: true})
  10. sp1 := t1.New("test123")
  11. ctx := context.Background()
  12. ctx = NewContext(ctx, sp1)
  13. sp2, ok := FromContext(ctx)
  14. if !ok {
  15. t.Fatal("nothing from context")
  16. }
  17. assert.Equal(t, sp1, sp2)
  18. }