Skip to content

Commit 14e2a33

Browse files
committed
Add README for testserver
1 parent ad80844 commit 14e2a33

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

testserver/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# cockroach-go Testserver
2+
3+
The `testserver` package helps running cockroachDB binary with tests. It
4+
automatically downloads the latest stable cockroach binary for your runtimeOS
5+
(Linux-amd64 and Darwin-amd64 only for now), or attempts to run "cockroach" from your PATH.
6+
7+
### Example
8+
To run the test server, call `NewTestServer(opts)` and with test server options.
9+
10+
Here's an example of starting a test server without server options (i.e. in `Insecure`
11+
mode).
12+
13+
```go
14+
import "github.com/cockroachdb/cockroach-go/v2/testserver"
15+
import "testing"
16+
import "time"
17+
18+
func TestRunServer(t *testing.T) {
19+
ts, err := testserver.NewTestServer()
20+
if err != nil {
21+
t.Fatal(err)
22+
}
23+
defer ts.Stop()
24+
25+
db, err := sql.Open("postgres", ts.PGURL().String())
26+
if err != nil {
27+
t.Fatal(err)
28+
}
29+
}
30+
```
31+
32+
**Note: please always use `testserver.NewTestServer()` to start a test server. Never use
33+
`testserver.Start()`.**
34+
35+
### Test Server Options
36+
37+
The default configuration is :
38+
39+
- in insecure mode, so not using TLS certificates to encrypt network;
40+
- storing data to memory, with 20% of hard drive space assigned to the node;
41+
- auto-downloading the latest stable release of cockroachDB.
42+
43+
You can also choose from the following options and pass them to `testserver.
44+
NewTestServer()`.
45+
46+
- **Secure Mode**: run a secure multi-node cluster locally, using TLS certificates to encrypt network communication.
47+
See also https://www.cockroachlabs.com/docs/stable/secure-a-cluster.html.
48+
- Usage: ```NewTestServer(testserver.SecureOpt())```
49+
- **Set Root User's Password**: set the given password for the root user for the
50+
PostgreSQL server, so to avoid having to use client certificates. This option can
51+
only be passed under secure mode.
52+
- Usage: ```NewTestServer(testserver.RootPasswordOpt
53+
(your_password))```
54+
- **Store On Disk**: store the database to the local disk. By default, the database is
55+
saved at `/tmp/cockroach-testserverxxxxxxxx`, with randomly generated `xxxxxxxx`
56+
postfix.
57+
- Usage: ```NewTestServer(testserver.StoreOnDiskOpt())```
58+
- **Set Memory Allocation for Databse Storage**: set the maximum percentage of
59+
total memory space assigned to store the database.
60+
See also https://www.cockroachlabs. com/docs/stable/cockroach-start.html.
61+
- Usage:
62+
```NewTestServer(testserver.SetStoreMemSizeOpt(0.3))```
63+
64+
### Test Server for Multi Tenants
65+
The usage of test server as a tenant server is still under development. Please
66+
check `testserver/tenant.go` for more information.

0 commit comments

Comments
 (0)