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

     1  // Copyright 2020 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 cli
    12  
    13  import (
    14  	"fmt"
    15  	"testing"
    16  
    17  	"github.com/cockroachdb/cockroach/pkg/base"
    18  	"github.com/cockroachdb/cockroach/pkg/roachpb"
    19  	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
    20  	"github.com/stretchr/testify/assert"
    21  )
    22  
    23  func TestTestServerArgsForTransientCluster(t *testing.T) {
    24  	defer leaktest.AfterTest(t)()
    25  
    26  	testCases := []struct {
    27  		nodeID            roachpb.NodeID
    28  		joinAddr          string
    29  		sqlPoolMemorySize int64
    30  		cacheSize         int64
    31  
    32  		expected base.TestServerArgs
    33  	}{
    34  		{
    35  			nodeID:            roachpb.NodeID(1),
    36  			joinAddr:          "127.0.0.1",
    37  			sqlPoolMemorySize: 2 << 10,
    38  			cacheSize:         1 << 10,
    39  			expected: base.TestServerArgs{
    40  				PartOfCluster:     true,
    41  				JoinAddr:          "127.0.0.1",
    42  				DisableTLSForHTTP: true,
    43  				SQLMemoryPoolSize: 2 << 10,
    44  				CacheSize:         1 << 10,
    45  			},
    46  		},
    47  		{
    48  			nodeID:            roachpb.NodeID(3),
    49  			joinAddr:          "127.0.0.1",
    50  			sqlPoolMemorySize: 4 << 10,
    51  			cacheSize:         4 << 10,
    52  			expected: base.TestServerArgs{
    53  				PartOfCluster:     true,
    54  				JoinAddr:          "127.0.0.1",
    55  				DisableTLSForHTTP: true,
    56  				SQLMemoryPoolSize: 4 << 10,
    57  				CacheSize:         4 << 10,
    58  			},
    59  		},
    60  	}
    61  
    62  	for _, tc := range testCases {
    63  		demoCtxTemp := demoCtx
    64  		demoCtx.sqlPoolMemorySize = tc.sqlPoolMemorySize
    65  		demoCtx.cacheSize = tc.cacheSize
    66  
    67  		actual := testServerArgsForTransientCluster(unixSocketDetails{}, tc.nodeID, tc.joinAddr, "")
    68  
    69  		assert.Len(t, actual.StoreSpecs, 1)
    70  		assert.Equal(
    71  			t,
    72  			fmt.Sprintf("demo-node%d", tc.nodeID),
    73  			actual.StoreSpecs[0].StickyInMemoryEngineID,
    74  		)
    75  
    76  		// We cannot compare these.
    77  		actual.Stopper = nil
    78  		actual.StoreSpecs = nil
    79  
    80  		assert.Equal(t, tc.expected, actual)
    81  
    82  		// Restore demoCtx state after each test.
    83  		demoCtx = demoCtxTemp
    84  	}
    85  }