github.com/searKing/golang/go@v1.2.117/expvar/leakvar_test.go (about)

     1  // Copyright 2022 The searKing Author. 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 expvar_test
     6  
     7  import (
     8  	"expvar"
     9  	"testing"
    10  
    11  	expvar_ "github.com/searKing/golang/go/expvar"
    12  )
    13  
    14  func TestLeak(t *testing.T) {
    15  	reqs := expvar_.NewLeak("requests")
    16  	if i := reqs.Value(); i != 0 {
    17  		t.Errorf("reqs.Value() = %v, want 0", i)
    18  	}
    19  	if reqs != expvar.Get("requests").(*expvar_.Leak) {
    20  		t.Errorf("Get() failed.")
    21  	}
    22  
    23  	reqs.Add(1)
    24  	reqs.Add(3)
    25  	if got := reqs.Value(); got != 4 {
    26  		t.Errorf("reqs.Value() = %v, want 4", got)
    27  	}
    28  
    29  	if got := reqs.String(); got != "[4 4]" {
    30  		t.Errorf("reqs.String() = %q, want %q", "[4 4]", got)
    31  	}
    32  
    33  	reqs.Add(-4)
    34  	if got := reqs.Value(); got != 0 {
    35  		t.Errorf("reqs.Value() = %v, want 4", got)
    36  	}
    37  
    38  	if got := reqs.String(); got != "[0 4]" {
    39  		t.Errorf("reqs.String() = %q, want %q", got, "[0 4]")
    40  	}
    41  	reqs.Add(1)
    42  	reqs.Done()
    43  	if got := reqs.Value(); got != 0 {
    44  		t.Errorf("reqs.Value() = %v, want 4", got)
    45  	}
    46  
    47  	if got := reqs.String(); got != "[0 5]" {
    48  		t.Errorf("reqs.String() = %q, want %q", got, "[0 5]")
    49  	}
    50  }