Skip to content

Commit

Permalink
Merge branch 'main' into run-lint-first
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya authored Dec 5, 2024
2 parents 1f63457 + 0bbab5e commit b1ce85f
Show file tree
Hide file tree
Showing 22 changed files with 602 additions and 500 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5
with:
go-version: '${{ inputs.go-version }}'
cache-dependency-path: '${{ inputs.project-directory }}/go.sum'
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
./scripts/check_environment.sh
- name: Test Summary
uses: test-summary/action@032c8a9cec6aaa3c20228112cae6ca10a3b29336 # v2.3
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 # v2.4
with:
paths: "**/${{ inputs.project-directory }}/TEST-unit*.xml"
if: always()
2 changes: 1 addition & 1 deletion .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
ref: ${{ github.event.client_payload.pull_request.head.ref }}

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5
with:
go-version-file: go.mod
id: go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-moby-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0
with:
results_file: results.sarif
results_format: sarif
Expand Down
2 changes: 1 addition & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ func (c *ContainerRequest) validateMounts() error {
if len(hostConfig.Binds) > 0 {
for _, bind := range hostConfig.Binds {
parts := strings.Split(bind, ":")
if len(parts) != 2 {
if len(parts) != 2 && len(parts) != 3 {
return fmt.Errorf("%w: %s", ErrInvalidBindMount, bind)
}
targetPath := parts[1]
Expand Down
26 changes: 24 additions & 2 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,33 @@ func Test_ContainerValidation(t *testing.T) {
},
{
Name: "Invalid bind mount",
ExpectedError: "invalid bind mount: /data:/data:/data",
ExpectedError: "invalid bind mount: /data:/data:a:b",
ContainerRequest: testcontainers.ContainerRequest{
Image: "redis:latest",
HostConfigModifier: func(hc *container.HostConfig) {
hc.Binds = []string{"/data:/data:/data"}
hc.Binds = []string{"/data:/data:a:b"}
},
},
},
{
Name: "bind-options/provided",
ContainerRequest: testcontainers.ContainerRequest{
Image: "redis:latest",
HostConfigModifier: func(hc *container.HostConfig) {
hc.Binds = []string{
"/a:/a:nocopy",
"/b:/b:ro",
"/c:/c:rw",
"/d:/d:z",
"/e:/e:Z",
"/f:/f:shared",
"/g:/g:rshared",
"/h:/h:slave",
"/i:/i:rslave",
"/j:/j:private",
"/k:/k:rprivate",
"/l:/l:ro,z,shared",
}
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions docs/features/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ The example will also create a client that will connect to the server using the
demonstrating how to use the generated certificate to communicate with a service.

<!--codeinclude-->
[Create a self-signed certificate](../../modules/cockroachdb/certs.go) inside_block:exampleSelfSignedCert
[Sign a self-signed certificate](../../modules/cockroachdb/certs.go) inside_block:exampleSignSelfSignedCert
[Create a self-signed certificate](../../modules/rabbitmq/examples_test.go) inside_block:exampleSelfSignedCert
[Sign a self-signed certificate](../../modules/rabbitmq/examples_test.go) inside_block:exampleSignSelfSignedCert
<!--/codeinclude-->
33 changes: 25 additions & 8 deletions docs/modules/cockroachdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The Testcontainers module for CockroachDB.

Please run the following command to add the CockroachDB module to your Go dependencies:

```
```shell
go get github.com/testcontainers/testcontainers-go/modules/cockroachdb
```

Expand Down Expand Up @@ -54,23 +54,33 @@ E.g. `Run(context.Background(), "cockroachdb/cockroach:latest-v23.1")`.

Set the database that is created & dialled with `cockroachdb.WithDatabase`.

#### Password authentication
#### User and Password

You can configured the container to create a user with a password by setting `cockroachdb.WithUser` and `cockroachdb.WithPassword`.

Disable insecure mode and connect with password authentication by setting `cockroachdb.WithUser` and `cockroachdb.WithPassword`.
`cockroachdb.WithPassword` is incompatible with `cockroachdb.WithInsecure`.

#### Store size

Control the maximum amount of memory used for storage, by default this is 100% but can be changed by provided a valid option to `WithStoreSize`. Checkout https://www.cockroachlabs.com/docs/stable/cockroach-start#store for the full range of options available.

#### TLS authentication

`cockroachdb.WithTLS` lets you provide the CA certificate along with the certicate and key for the node & clients to connect with.
Internally CockroachDB requires a client certificate for the user to connect with.
`cockroachdb.WithInsecure` lets you disable the use of TLS on connections.

`cockroachdb.WithInsecure` is incompatible with `cockroachdb.WithPassword`.

#### Initialization Scripts

`cockroachdb.WithInitScripts` adds the given scripts to those automatically run when the container starts.
These will be ignored if data exists in the `/cockroach/cockroach-data` directory within the container.

A helper `cockroachdb.NewTLSConfig` exists to generate all of this for you.
`cockroachdb.WithNoClusterDefaults` disables the default cluster settings script.

!!!warning
When TLS is enabled there's a very small, unlikely chance that the underlying driver can panic when registering the driver as part of waiting for CockroachDB to be ready to accept connections. If this is repeatedly happening please open an issue.
Without this option Cockroach containers run `data/cluster-defaults.sql` on startup
which configures the settings recommended by Cockroach Labs for
[local testing clusters](https://www.cockroachlabs.com/docs/stable/local-testing)
unless data exists in the `/cockroach/cockroach-data` directory within the container.

### Container Methods

Expand All @@ -87,3 +97,10 @@ Same as `ConnectionString` but any error to generate the address will raise a pa
#### TLSConfig

Returns `*tls.Config` setup to allow you to dial your client over TLS, if enabled, else this will error with `cockroachdb.ErrTLSNotEnabled`.

!!!info
The `TLSConfig()` function is deprecated and will be removed in the next major release of _Testcontainers for Go_.

#### ConnectionConfig

Returns `*pgx.ConnConfig` which can be passed to `pgx.ConnectConfig` to open a new connection.
11 changes: 10 additions & 1 deletion docs/modules/nats.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ These arguments are passed to the NATS server when it starts, as part of the com
[Passing arguments](../../modules/nats/examples_test.go) inside_block:withArguments
<!--/codeinclude-->
#### Custom configuration file
- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>
It's possible to pass a custom config file to NATS container using `nats.WithConfigFile(strings.NewReader(config))`. The content of `io.Reader` is passed as a `-config /etc/nats.conf` arguments to an entrypoint.

!!! note
Changing the connectivity (listen address or ports) can break the container setup. So configuration must be done with care.

### Container Methods

The NATS container exposes the following methods:
Expand Down Expand Up @@ -102,4 +111,4 @@ Exactly like `ConnectionString`, but it panics if an error occurs, returning jus
<!--codeinclude-->
[NATS Cluster](../../modules/nats/examples_test.go) inside_block:cluster
<!--/codeinclude-->
<!--/codeinclude-->
15 changes: 8 additions & 7 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ import (
)

// Logger is the default log instance
var Logger Logging = log.New(os.Stderr, "", log.LstdFlags)
var Logger Logging = &noopLogger{}

func init() {
for _, arg := range os.Args {
if strings.EqualFold(arg, "-test.v=true") || strings.EqualFold(arg, "-v") {
return
// Enable default logger in the testing with a verbose flag.
if testing.Testing() {
// Parse manually because testing.Verbose() panics unless flag.Parse() has done.
for _, arg := range os.Args {
if strings.EqualFold(arg, "-test.v=true") || strings.EqualFold(arg, "-v") {
Logger = log.New(os.Stderr, "", log.LstdFlags)
}
}
}

// If we are not running in verbose mode, we configure a noop logger by default.
Logger = &noopLogger{}
}

// Validate our types implement the required interfaces.
Expand Down
67 changes: 0 additions & 67 deletions modules/cockroachdb/certs.go

This file was deleted.

Loading

0 comments on commit b1ce85f

Please sign in to comment.