Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: use Go testable examples in modules #1603

Merged
merged 39 commits into from
Sep 11, 2023

Conversation

mdelapenya
Copy link
Collaborator

@mdelapenya mdelapenya commented Sep 8, 2023

What does this PR do?

This PR adds a examples_test.go file in all Go modules, adding there testable examples (func ExampleRunContainer())

At the same time, we are adapting the code snippets that are embedded into the docs site to use this example functions instead of the test ones. In certain cases, we have refactored the test cases to follow a better structure that adapts to the testable examples.

We are aware that some Example functions could be duplication other existing tests, that's way we have removed those that collided.

During the refactor of the docs, we found useful to include docs on how to create a Docker network using the library, so docs have been added for that feature.

Why is it important?

The code snippets in docs won't contain references to testing libraries such as testing or testify, and the examples will appear in pgk.go.dev, which is important for our users to see real, executable test examples.

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner September 8, 2023 10:00
@mdelapenya mdelapenya added the documentation Docs, docs, docs. label Sep 8, 2023
@mdelapenya mdelapenya self-assigned this Sep 8, 2023
@netlify
Copy link

netlify bot commented Sep 8, 2023

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 1f64536
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/64ff2a6eb1df03000829f79d
😎 Deploy Preview https://deploy-preview-1603--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

mmorel-35 and others added 11 commits September 11, 2023 12:38
…ult (testcontainers#1566)

* chore(deps): bump github.com/hashicorp/vault-client-go in /modules/vault

Bumps [github.com/hashicorp/vault-client-go](https://github.com/hashicorp/vault-client-go) from 0.2.0 to 0.3.3.
- [Release notes](https://github.com/hashicorp/vault-client-go/releases)
- [Changelog](https://github.com/hashicorp/vault-client-go/blob/main/CHANGELOG.md)
- [Commits](hashicorp/vault-client-go@v0.2.0...v0.3.3)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/vault-client-go
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* up

* Update vault_test.go

* Update vault_test.go

* Update vault_test.go

* Update vault_test.go

* Update vault_test.go

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com>
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
* ci(lint): enable errorlint linter

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

* Apply suggestions from code review

Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>

---------

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>
* main:
  ci(lint): enable errorlint linter (testcontainers#1604)
  ci(lint): enable gocritic linter (testcontainers#1605)
  chore(deps): bump github.com/hashicorp/vault-client-go in /modules/vault (testcontainers#1566)
@sonarcloud
Copy link

sonarcloud bot commented Sep 11, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.3% 0.3% Duplication

defaultWaitStrategies.Strategies = append(
defaultWaitStrategies.Strategies,
// clone defaultWaitStrategies
ss := []wait.Strategy{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discovered a bug here in the case the tests were run sequentially, as the default strategies variable was overridden, causing the with_transactions test case to fail because it was expecting the wait strategy for with_functions_workers. Fixing it here to avoid the test failures that were discovered on this PR

@@ -154,7 +154,7 @@ func (c *DockerContainer) startedHook(ctx context.Context) error {

// printLogs is a helper function that will print the logs of a Docker container
// We are going to use this helper function to inform the user of the logs when an error occurs
func (c *DockerContainer) printLogs(ctx context.Context) {
func (c *DockerContainer) printLogs(ctx context.Context, cause error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to print out the original error that caused the hooks to stop

@mdelapenya mdelapenya merged commit 58f1778 into testcontainers:main Sep 11, 2023
101 checks passed
@mdelapenya mdelapenya deleted the migrate-examples branch September 11, 2023 15:59
mdelapenya added a commit that referenced this pull request Sep 12, 2023
…containerd-1.7.5

* main:
  chore: always generate the examples including a explicit image (#1611)
  chore: support linting all modules locally (#1609)
  ci(sonarcloud): run only when not root-less (#1608)
  remove extra equal in sonar.organization (#1607)
  chore(ci): enable code coverage on Sonarcloud (#1518)
  docs: use Go testable examples in modules (#1603)
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Sep 12, 2023
* main:
  chore: always generate the examples including a explicit image (testcontainers#1611)
  chore: support linting all modules locally (testcontainers#1609)
  ci(sonarcloud): run only when not root-less (testcontainers#1608)
  remove extra equal in sonar.organization (testcontainers#1607)
  chore(ci): enable code coverage on Sonarcloud (testcontainers#1518)
  docs: use Go testable examples in modules (testcontainers#1603)
  ci(lint): enable errorlint linter (testcontainers#1604)
  ci(lint): enable gocritic linter (testcontainers#1605)
  chore(deps): bump github.com/hashicorp/vault-client-go in /modules/vault (testcontainers#1566)
  ci(security): setup codeql scan  (testcontainers#1606)
  chore(deps): bump github.com/cyphar/filepath-securejoin (testcontainers#1601)
  chore: generate Go examples for new modules (testcontainers#1600)
  chore: generate Go examples for new modules (testcontainers#1600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Docs, docs, docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: incomplete documentation for postgres example
2 participants