github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/net/trace/trace_test.go (about)

     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  
     5  package trace
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  type s struct{}
    13  
    14  func (s) String() string { return "lazy string" }
    15  
    16  // TestReset checks whether all the fields are zeroed after reset.
    17  func TestReset(t *testing.T) {
    18  	tr := New("foo", "bar")
    19  	tr.LazyLog(s{}, false)
    20  	tr.LazyPrintf("%d", 1)
    21  	tr.SetRecycler(func(_ interface{}) {})
    22  	tr.SetTraceInfo(3, 4)
    23  	tr.SetMaxEvents(100)
    24  	tr.SetError()
    25  	tr.Finish()
    26  
    27  	tr.(*trace).reset()
    28  
    29  	if !reflect.DeepEqual(tr, new(trace)) {
    30  		t.Errorf("reset didn't clear all fields: %+v", tr)
    31  	}
    32  }
    33  
    34  // TestResetLog checks whether all the fields are zeroed after reset.
    35  func TestResetLog(t *testing.T) {
    36  	el := NewEventLog("foo", "bar")
    37  	el.Printf("message")
    38  	el.Errorf("error")
    39  	el.Finish()
    40  
    41  	el.(*eventLog).reset()
    42  
    43  	if !reflect.DeepEqual(el, new(eventLog)) {
    44  		t.Errorf("reset didn't clear all fields: %+v", el)
    45  	}
    46  }