github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/roachpb/span_group_test.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package roachpb
    12  
    13  import "testing"
    14  
    15  func TestSpanGroup(t *testing.T) {
    16  	g := &SpanGroup{}
    17  
    18  	be := makeSpan("b-e")
    19  
    20  	if g.Contains(Key("a")) {
    21  		t.Fatal("empty group should not contain a")
    22  	}
    23  	if !g.Add(be) {
    24  		t.Fatal("adding b-e to empty should expand it")
    25  	}
    26  	if g.Add(be) {
    27  		t.Fatal("adding  b-e to b-e should not expand it")
    28  	}
    29  	if g.Add(makeSpan("c-d")) {
    30  		t.Fatal("adding c-d to b-e should not expand it")
    31  	}
    32  	if g.Add(makeSpan("b-d")) {
    33  		t.Fatal("adding b-d to b-e should not expand it")
    34  	}
    35  	if g.Add(makeSpan("d-e")) {
    36  		t.Fatal("adding d-e to b-e should not expand it")
    37  	}
    38  	if got, expected := g.Len(), 1; got != expected {
    39  		t.Fatalf("got %d, expected %d", got, expected)
    40  	}
    41  	if got, expected := g.Slice(), be; len(got) != 1 || !got[0].Equal(expected) {
    42  		t.Fatalf("got %v, expected %v", got, expected)
    43  	}
    44  	for _, k := range []string{"b", "c", "d"} {
    45  		if !g.Contains(Key(k)) {
    46  			t.Fatalf("span b-e should contain %q", k)
    47  		}
    48  	}
    49  	for _, k := range []string{"a", "e", "f"} {
    50  		if g.Contains(Key(k)) {
    51  			t.Fatalf("span b-e should not contain %q", k)
    52  		}
    53  	}
    54  }