-
-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/logging-deadlock
- Loading branch information
Showing
133 changed files
with
1,704 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// This test is testing very internal logic that should not be exported away from this package. We'll | ||
// leave it in the main testcontainers package. Do not use for user facing examples. | ||
package testcontainers | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestContainerFileValidation(t *testing.T) { | ||
type ContainerFileValidationTestCase struct { | ||
Name string | ||
ExpectedError error | ||
File ContainerFile | ||
} | ||
|
||
f, err := os.Open(filepath.Join(".", "testdata", "hello.sh")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
testTable := []ContainerFileValidationTestCase{ | ||
{ | ||
Name: "valid container file: has hostfilepath", | ||
File: ContainerFile{ | ||
HostFilePath: "/path/to/host", | ||
ContainerFilePath: "/path/to/container", | ||
}, | ||
}, | ||
{ | ||
Name: "valid container file: has reader", | ||
File: ContainerFile{ | ||
Reader: f, | ||
ContainerFilePath: "/path/to/container", | ||
}, | ||
}, | ||
{ | ||
Name: "invalid container file", | ||
ExpectedError: errors.New("either HostFilePath or Reader must be specified"), | ||
File: ContainerFile{ | ||
HostFilePath: "", | ||
Reader: nil, | ||
ContainerFilePath: "/path/to/container", | ||
}, | ||
}, | ||
{ | ||
Name: "invalid container file", | ||
ExpectedError: errors.New("ContainerFilePath must be specified"), | ||
File: ContainerFile{ | ||
HostFilePath: "/path/to/host", | ||
ContainerFilePath: "", | ||
}, | ||
}, | ||
} | ||
|
||
for _, testCase := range testTable { | ||
t.Run(testCase.Name, func(t *testing.T) { | ||
err := testCase.File.validate() | ||
switch { | ||
case err == nil && testCase.ExpectedError == nil: | ||
return | ||
case err == nil && testCase.ExpectedError != nil: | ||
t.Errorf("did not receive expected error: %s", testCase.ExpectedError.Error()) | ||
case err != nil && testCase.ExpectedError == nil: | ||
t.Errorf("received unexpected error: %s", err.Error()) | ||
case err.Error() != testCase.ExpectedError.Error(): | ||
t.Errorf("errors mismatch: %s != %s", err.Error(), testCase.ExpectedError.Error()) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Registry | ||
|
||
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> | ||
|
||
## Introduction | ||
|
||
The Testcontainers module for Registry. | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Please run the following command to add the Registry module to your Go dependencies: | ||
|
||
``` | ||
go get github.com/testcontainers/testcontainers-go/modules/registry | ||
``` | ||
|
||
## Usage example | ||
|
||
<!--codeinclude--> | ||
[Creating a Registry container](../../modules/registry/examples_test.go) inside_block:runRegistryContainer | ||
<!--/codeinclude--> | ||
|
||
## Module reference | ||
|
||
The Registry module exposes one entrypoint function to create the Registry container, and this function receives two parameters: | ||
|
||
```golang | ||
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*RegistryContainer, error) | ||
``` | ||
|
||
- `context.Context`, the Go context. | ||
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options. | ||
|
||
### Container Options | ||
|
||
When starting the Registry container, you can pass options in a variadic way to configure it. | ||
|
||
#### Image | ||
|
||
If you need to set a different Registry Docker image, you can use `testcontainers.WithImage` with a valid Docker image | ||
for Registry. E.g. `testcontainers.WithImage("registry:2.8.3")`. | ||
|
||
{% include "../features/common_functional_options.md" %} | ||
|
||
#### With Authentication | ||
|
||
It's possible to enable authentication for the Registry container. By default, it is disabled, but you can enable it in two ways: | ||
- You can use `WithHtpasswd` to enable authentication with a string representing the contents of a `htpasswd` file. | ||
A temporary file will be created with the contents of the string and copied to the container. | ||
- You can use `WithHtpasswdFile` to copy a `htpasswd` file from your local filesystem to the container. | ||
In both cases, the `htpasswd` file will be copied into the `/auth` directory inside the container. | ||
<!--codeinclude--> | ||
[Htpasswd string](../../modules/registry/registry_test.go) inside_block:htpasswdString | ||
[Htpasswd file](../../modules/registry/examples_test.go) inside_block:htpasswdFile | ||
<!--/codeinclude--> | ||
#### WithData | ||
In the case you want to initialise the Registry with your own images, you can use `WithData` to copy a directory from your local filesystem to the container. | ||
The directory will be copied into the `/data` directory inside the container. | ||
The format of the directory should be the same as the one used by the Registry to store images. | ||
Otherwise, the Registry will start but you won't be able to read any images from it. | ||
|
||
<!--codeinclude--> | ||
[Including data](../../modules/registry/examples_test.go) inside_block:htpasswdFile | ||
<!--/codeinclude--> | ||
|
||
### Container Methods | ||
|
||
The Registry container exposes the following methods: | ||
|
||
#### Address | ||
|
||
This method returns the HTTP address string to connect to the Distribution Registry, so that you can use to connect to the Registry. | ||
E.g. `http://localhost:32878/v2/_catalog`. | ||
|
||
<!--codeinclude--> | ||
[HTTP Address](../../modules/registry/registry_test.go) inside_block:httpAddress | ||
<!--/codeinclude--> | ||
|
||
#### ImageExists | ||
|
||
The `ImageExists` method allows to check if an image exists in the Registry. It receives the Go context and the image reference as parameters. | ||
|
||
!!! info | ||
The image reference should be in the format `my-registry:port/image:tag` in order to be pushed to the Registry. | ||
|
||
#### PushImage | ||
|
||
The `PushImage` method allows to push an image to the Registry. It receives the Go context and the image reference as parameters. | ||
|
||
!!! info | ||
The image reference should be in the format `my-registry:port/image:tag` in order to be pushed to the Registry. | ||
|
||
<!--codeinclude--> | ||
[Pushing images to the registry](../../modules/registry/examples_test.go) inside_block:pushingImage | ||
<!--/codeinclude--> | ||
|
||
If the push operation is successful, the method will internally wait for the image to be available in the Registry, querying the Registry API, returning an error in case of any failure (e.g. pushing or waiting for the image). | ||
|
||
#### DeleteImage | ||
|
||
The `DeleteImage` method allows to delete an image from the Registry. It receives the Go context and the image reference as parameters. | ||
|
||
!!! info | ||
The image reference should be in the format `image:tag` in order to be deleted from the Registry. | ||
|
||
<!--codeinclude--> | ||
[Deleting images from the registry](../../modules/registry/examples_test.go) inside_block:deletingImage | ||
<!--/codeinclude--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.