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

     1  // Copyright 2016 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 base_test
    12  
    13  import (
    14  	"context"
    15  	"testing"
    16  
    17  	"github.com/cockroachdb/cockroach/pkg/base"
    18  	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
    19  )
    20  
    21  func TestNodeIDContainer(t *testing.T) {
    22  	defer leaktest.AfterTest(t)()
    23  	n := &base.NodeIDContainer{}
    24  
    25  	if val := n.Get(); val != 0 {
    26  		t.Errorf("initial value should be 0, not %d", val)
    27  	}
    28  	if str := n.String(); str != "?" {
    29  		t.Errorf("initial string should be ?, not %s", str)
    30  	}
    31  
    32  	for i := 0; i < 2; i++ {
    33  		n.Set(context.Background(), 5)
    34  		if val := n.Get(); val != 5 {
    35  			t.Errorf("value should be 5, not %d", val)
    36  		}
    37  		if str := n.String(); str != "5" {
    38  			t.Errorf("string should be 5, not %s", str)
    39  		}
    40  	}
    41  
    42  	n.Reset(6)
    43  	if val := n.Get(); val != 6 {
    44  		t.Errorf("value should be 6, not %d", val)
    45  	}
    46  	if str := n.String(); str != "6" {
    47  		t.Errorf("string should be 6, not %s", str)
    48  	}
    49  }