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

     1  // Copyright 2015 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 testutils
    12  
    13  import (
    14  	"github.com/cockroachdb/cockroach/pkg/base"
    15  	"github.com/cockroachdb/cockroach/pkg/security"
    16  )
    17  
    18  // NewNodeTestBaseContext creates a base context for testing. This uses
    19  // embedded certs and the default node user. The default node user has both
    20  // server and client certificates.
    21  func NewNodeTestBaseContext() *base.Config {
    22  	return NewTestBaseContext(security.NodeUser)
    23  }
    24  
    25  // NewTestBaseContext creates a secure base context for user.
    26  func NewTestBaseContext(user string) *base.Config {
    27  	cfg := &base.Config{
    28  		Insecure: false,
    29  		User:     user,
    30  	}
    31  	FillCerts(cfg)
    32  	return cfg
    33  }
    34  
    35  // FillCerts sets the certs on a base.Config.
    36  func FillCerts(cfg *base.Config) {
    37  	cfg.SSLCertsDir = security.EmbeddedCertsDir
    38  }