github.com/GoWebProd/gip@v0.0.0-20230623090727-b60d41d5d320/safe/cleanup_test.go (about)

     1  package safe
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  type testStruct struct {
     8  	a string
     9  	b int
    10  	c bool
    11  }
    12  
    13  func TestCleanup(t *testing.T) {
    14  	var ts testStruct
    15  
    16  	ts.a = "test"
    17  	ts.b = 5
    18  	ts.c = true
    19  
    20  	Cleanup(&ts)
    21  
    22  	if ts.a != "" || ts.b != 0 || ts.c {
    23  		t.Fatalf("bad memset: %+v", ts)
    24  	}
    25  }
    26  
    27  func BenchmarkCleanup(b *testing.B) {
    28  	for i := 0; i < b.N; i++ {
    29  		var ts testStruct
    30  
    31  		ts.a = "test"
    32  		ts.b = 5
    33  		ts.c = true
    34  
    35  		Cleanup(&ts)
    36  	}
    37  }