github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/tests/impure_builtin_test.go (about)

     1  // Copyright 2017 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 tests_test
    12  
    13  import (
    14  	"context"
    15  	"testing"
    16  
    17  	"github.com/cockroachdb/cockroach/pkg/base"
    18  	"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
    19  	"github.com/cockroachdb/cockroach/pkg/testutils/testcluster"
    20  	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
    21  	"github.com/cockroachdb/cockroach/pkg/util/uuid"
    22  )
    23  
    24  func TestClusterID(t *testing.T) {
    25  	defer leaktest.AfterTest(t)()
    26  
    27  	testClusterArgs := base.TestClusterArgs{
    28  		ReplicationMode: base.ReplicationAuto,
    29  	}
    30  	tc := testcluster.StartTestCluster(t, 3, testClusterArgs)
    31  	defer tc.Stopper().Stop(context.Background())
    32  
    33  	for i := 0; i < 3; i++ {
    34  		db := sqlutils.MakeSQLRunner(tc.Conns[i])
    35  		var clusterID uuid.UUID
    36  		db.QueryRow(t, "SELECT crdb_internal.cluster_id()").Scan(&clusterID)
    37  		if id := tc.Servers[0].ClusterID(); id != clusterID {
    38  			t.Fatalf("expected %v, got %v", id, clusterID)
    39  		}
    40  	}
    41  }