package
2.4.0
Repository: https://github.com/cockroachdb/cockroach-go.git
Documentation: pkg.go.dev

# README

cockroach-go Testserver

The testserver package helps running cockroachDB binary with tests. It automatically downloads the latest stable cockroach binary for your runtimeOS, or attempts to run "cockroach" from your PATH.

Example

To run the test server, call NewTestServer(opts) and with test server options.

Here's an example of starting a test server without server options (i.e. in Insecure mode).

  import "github.com/cockroachdb/cockroach-go/v2/testserver"
  import "testing"
  import "time"

  func TestRunServer(t *testing.T) {
     ts, err := testserver.NewTestServer()
     if err != nil {
       t.Fatal(err)
     }
     defer ts.Stop()

     db, err := sql.Open("postgres", ts.PGURL().String())
     if err != nil {
       t.Fatal(err)
     }
   }

Note: please always use testserver.NewTestServer() to start a test server. Never use testserver.Start().

Test Server Options

The default configuration is :

  • in insecure mode, so not using TLS certificates to encrypt network;
  • storing data to memory, with 20% of hard drive space assigned to the node;
  • auto-downloading the latest stable release of cockroachDB.

You can also choose from the following options and pass them to testserver. NewTestServer().

  • Secure Mode: run a secure multi-node cluster locally, using TLS certificates to encrypt network communication. See also https://www.cockroachlabs.com/docs/stable/secure-a-cluster.html.
    • Usage: NewTestServer(testserver.SecureOpt())
  • Set Root User's Password: set the given password for the root user for the PostgreSQL server, so to avoid having to use client certificates. This option can only be passed under secure mode.
    • Usage: NewTestServer(testserver.RootPasswordOpt (your_password))
  • Store On Disk: store the database to the local disk. By default, the database is saved at /tmp/cockroach-testserverxxxxxxxx, with randomly generated xxxxxxxx postfix.
    • Usage: NewTestServer(testserver.StoreOnDiskOpt())
  • Set Memory Allocation for Databse Storage: set the maximum percentage of total memory space assigned to store the database. See also https://www.cockroachlabs. com/docs/stable/cockroach-start.html.
    • Usage: NewTestServer(testserver.SetStoreMemSizeOpt(0.3))

Test Server for Multi Tenants

The usage of test server as a tenant server is still under development. Please check testserver/tenant.go for more information.

# Packages

No description provided by the author

# Functions

AddHttpPortOpt is a TestServer option that can be passed to NewTestServer to specify the http ports for the Cockroach nodes.
AddListenAddrPortOpt is a TestServer option that can be passed to NewTestServer to specify the ports for the Cockroach nodes.
CacheSizeOpt sets the proportion of available memory that is allocated to the CockroachDB cache.
CockroachBinaryPathOpt is a TestServer option that can be passed to NewTestServer to specify the path of the cockroach binary.
CockroachLogsDirOpt allows callers to control where the stdout and stderr of cockroach processes created by the testserver are located.
CustomVersionOpt is a TestServer option that can be passed to NewTestServer to download the a specific version of CRDB.
DownloadBinary saves the latest version of CRDB into a local binary file, and returns the path for this local binary.
DownloadFromURL starts a download of the cockroach binary from the given URL.
EnvVarOpt is a list of environment variables to be passed to the start command.
ExposeConsoleOpt is a TestServer option that can be passed to NewTestServer to expose the console of the server on the given port.
ExternalIODirOpt is a TestServer option that can be passed to NewTestServer to specify the external IO directory to be used for the cluster.
GetDownloadFilename returns the local filename of the downloaded CRDB binary file.
GetDownloadURL returns the URL of a CRDB download.
No description provided by the author
ListenAddrHostOpt is a TestServer option that can be passed to NewTestServer to specify the host for Cockroach to listen on.
LocalityFlagsOpt is used to specify the --locality flag for each node.
NewDBForTest creates a new CockroachDB TestServer instance and opens a SQL database connection to it.
NewDBForTestWithDatabase creates a new CockroachDB TestServer instance and opens a SQL database connection to it.
NewTestServer creates a new TestServer and starts it.
NonStableDbOpt is a TestServer option that can be passed to NewTestServer to download the latest beta version of CRDB, but not necessary a stable one.
No description provided by the author
RootPasswordOpt is a TestServer option that, when passed to NewTestServer, sets the given password for the root user (and returns a URL using it from PGURL().
SecureOpt is a TestServer option that can be passed to NewTestServer to enable secure mode.
SetStoreMemSizeOpt is a TestServer option that can be passed to NewTestServer to set the proportion of available memory that is allocated to the test server.
StopDownloadInMiddleOpt is a TestServer option used only in testing.
StoreOnDiskOpt is a TestServer option that can be passed to NewTestServer to enable storing database in memory.
No description provided by the author
No description provided by the author

# Structs

Release contains the information we extract from the YAML file in `releaseDataURL`.
No description provided by the author

# Interfaces

TestServer is a helper to run a real cockroach node.

# Type aliases

TestServerOpt is passed to NewTestServer.