github.com/aavshr/aws-sdk-go@v1.41.3/aws/csm/metric_chan_test.go (about)

     1  package csm
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestMetricChanPush(t *testing.T) {
     8  	ch := newMetricChan(5)
     9  	defer close(ch.ch)
    10  
    11  	pushed := ch.Push(metric{})
    12  	if !pushed {
    13  		t.Errorf("expected metrics to be pushed")
    14  	}
    15  
    16  	if e, a := 1, len(ch.ch); e != a {
    17  		t.Errorf("expected %d, but received %d", e, a)
    18  	}
    19  }
    20  
    21  func TestMetricChanPauseContinue(t *testing.T) {
    22  	ch := newMetricChan(5)
    23  	defer close(ch.ch)
    24  	ch.Pause()
    25  
    26  	if !ch.IsPaused() {
    27  		t.Errorf("expected to be paused, but did not pause properly")
    28  	}
    29  
    30  	ch.Continue()
    31  	if ch.IsPaused() {
    32  		t.Errorf("expected to be not paused, but did not continue properly")
    33  	}
    34  
    35  	pushed := ch.Push(metric{})
    36  	if !pushed {
    37  		t.Errorf("expected metrics to be pushed")
    38  	}
    39  
    40  	if e, a := 1, len(ch.ch); e != a {
    41  		t.Errorf("expected %d, but received %d", e, a)
    42  	}
    43  }
    44  
    45  func TestMetricChanPushWhenPaused(t *testing.T) {
    46  	ch := newMetricChan(5)
    47  	defer close(ch.ch)
    48  	ch.Pause()
    49  
    50  	pushed := ch.Push(metric{})
    51  	if pushed {
    52  		t.Errorf("expected metrics to not be pushed")
    53  	}
    54  
    55  	if e, a := 0, len(ch.ch); e != a {
    56  		t.Errorf("expected %d, but received %d", e, a)
    57  	}
    58  }
    59  
    60  func TestMetricChanNonBlocking(t *testing.T) {
    61  	ch := newMetricChan(0)
    62  	defer close(ch.ch)
    63  
    64  	pushed := ch.Push(metric{})
    65  	if pushed {
    66  		t.Errorf("expected metrics to be not pushed")
    67  	}
    68  
    69  	if e, a := 0, len(ch.ch); e != a {
    70  		t.Errorf("expected %d, but received %d", e, a)
    71  	}
    72  }