...

Source file src/go.opentelemetry.io/otel/sdk/trace/evictedqueue_test.go

Documentation: go.opentelemetry.io/otel/sdk/trace

     1  // Copyright The OpenTelemetry Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package trace
    16  
    17  import (
    18  	"reflect"
    19  	"testing"
    20  )
    21  
    22  func init() {
    23  }
    24  
    25  func TestAdd(t *testing.T) {
    26  	q := newEvictedQueue(3)
    27  	q.add("value1")
    28  	q.add("value2")
    29  	if wantLen, gotLen := 2, len(q.queue); wantLen != gotLen {
    30  		t.Errorf("got queue length %d want %d", gotLen, wantLen)
    31  	}
    32  }
    33  
    34  func (eq *evictedQueue) queueToArray() []string {
    35  	arr := make([]string, 0)
    36  	for _, value := range eq.queue {
    37  		arr = append(arr, value.(string))
    38  	}
    39  	return arr
    40  }
    41  
    42  func TestDropCount(t *testing.T) {
    43  	q := newEvictedQueue(3)
    44  	q.add("value1")
    45  	q.add("value2")
    46  	q.add("value3")
    47  	q.add("value1")
    48  	q.add("value4")
    49  	if wantLen, gotLen := 3, len(q.queue); wantLen != gotLen {
    50  		t.Errorf("got queue length %d want %d", gotLen, wantLen)
    51  	}
    52  	if wantDropCount, gotDropCount := 2, q.droppedCount; wantDropCount != gotDropCount {
    53  		t.Errorf("got drop count %d want %d", gotDropCount, wantDropCount)
    54  	}
    55  	wantArr := []string{"value3", "value1", "value4"}
    56  	gotArr := q.queueToArray()
    57  
    58  	if wantLen, gotLen := len(wantArr), len(gotArr); gotLen != wantLen {
    59  		t.Errorf("got array len %d want %d", gotLen, wantLen)
    60  	}
    61  
    62  	if !reflect.DeepEqual(gotArr, wantArr) {
    63  		t.Errorf("got array = %#v; want %#v", gotArr, wantArr)
    64  	}
    65  }
    66  

View as plain text