trace_test.go 1004 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package trace
  5. import (
  6. "reflect"
  7. "testing"
  8. )
  9. type s struct{}
  10. func (s) String() string { return "lazy string" }
  11. // TestReset checks whether all the fields are zeroed after reset.
  12. func TestReset(t *testing.T) {
  13. tr := New("foo", "bar")
  14. tr.LazyLog(s{}, false)
  15. tr.LazyPrintf("%d", 1)
  16. tr.SetRecycler(func(_ interface{}) {})
  17. tr.SetTraceInfo(3, 4)
  18. tr.SetMaxEvents(100)
  19. tr.SetError()
  20. tr.Finish()
  21. tr.(*trace).reset()
  22. if !reflect.DeepEqual(tr, new(trace)) {
  23. t.Errorf("reset didn't clear all fields: %+v", tr)
  24. }
  25. }
  26. // TestResetLog checks whether all the fields are zeroed after reset.
  27. func TestResetLog(t *testing.T) {
  28. el := NewEventLog("foo", "bar")
  29. el.Printf("message")
  30. el.Errorf("error")
  31. el.Finish()
  32. el.(*eventLog).reset()
  33. if !reflect.DeepEqual(el, new(eventLog)) {
  34. t.Errorf("reset didn't clear all fields: %+v", el)
  35. }
  36. }