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

[Documentation]: The docs don't always prepend the package to types #2180

Open
Minivera opened this issue Jan 31, 2024 · 4 comments · May be fixed by #2202
Open

[Documentation]: The docs don't always prepend the package to types #2180

Minivera opened this issue Jan 31, 2024 · 4 comments · May be fixed by #2202
Labels
documentation Docs, docs, docs.

Comments

@Minivera
Copy link
Contributor

Minivera commented Jan 31, 2024

Proposal

In the docs, many pages have code example you can copy, but those examples don't always contain the package that contains the structs used in the example as a prefix, this is the case for the Dockerfile docs, parts of the networking docs, and the files and mounts docs, to name a few.

This makes this code not directly usable when a user wants to try things out by first copy/pasting the example, then modifying once they see what happens. It's a minor thing, but testcontainers. needs to be prefixed to every struct every time they copy something, which can lead to errors if they forget to do so.

It'd be great if the docs could include these prefix on all structs, or possibly have the examples in context as a separate tab in the code blocks, so we can see the code used in a real test.

@Minivera Minivera added the enhancement New feature or request label Jan 31, 2024
@mdelapenya mdelapenya added documentation Docs, docs, docs. and removed enhancement New feature or request labels Jan 31, 2024
@mdelapenya
Copy link
Collaborator

Thanks for opening this issue, but I'm afraid it will not be as easy: the docs site is able to embed files from the source code, and we do have two types of test files where to grab those code snippets:

  • testable examples that directly land into pkg.go.dev, This is the preferred place to get the code snippets, as they don't have references to the testing library and assertions
  • real tests. They usually have the same package, e.g. testcontainers , instead of testcontainers_test which would enforce the package namespace in the code snippets. In the modules, we enforce that pattern thanks to the module generator tool, but not in the library (yet).

I'd be more than happy with having more hands rewriting all test files with this "_test" pattern 😄 As a direct consequence, all code snippets that are embedded from the test files will automatically receive the update.

@Minivera
Copy link
Contributor Author

I'm more than open to make that PR if it'd help 🙂 Though, pure curiosity, would it be doable to potentially transform the generated docs HTML/content (not sure how the docs are generated, yet) once it has been generated? Maybe we could look at keeping a reference to all the structs from testcontainers and see if they are missing the prefix, and add it post generation if it's missing it? Just an idea.

@mdelapenya
Copy link
Collaborator

We currently use mkdocs as docs system, and we are in the middle of merging all the Testcontainers language's docs to one single place (e.g. from golang.testcontainers.org to testcontainers.com). So I'm sure once there, we could find a better way to auto-generate things as you suggest.

In the mean time, I'd go with the test packages.

Minivera added a commit to Minivera/testcontainers-go that referenced this issue Feb 6, 2024
…mports

As discussed in testcontainers#2180, the imported examples from tests for the docs from lack the package prefix before the imports, which leads to the example not being directly copy/paste-able. To solve the issue it was suggested to create a `testcontainers_test` package for the example tests and to convert everything.

I did my best to convert all the tests in a way that makes sense, and I extracted any test that would import very internal things that we should not export. Some of the tests had to be slightly rewritten (the lifecycle tests in particular), but they should stay pretty much the same.

Test by running all the root unit tests, they should all work as expected. The examples in the docs should all have the packages as prefixes now.
@Minivera
Copy link
Contributor Author

Minivera commented Feb 6, 2024

I started a PR with your suggested changes for the test packages, let me know if that's not what you had in mind 😄

Minivera added a commit to Minivera/testcontainers-go that referenced this issue Feb 16, 2024
This work has been extracted from testcontainers#2202 and is related to testcontainers#2180. See the original PR for the full context and reasoning.
Minivera added a commit to Minivera/testcontainers-go that referenced this issue Feb 22, 2024
This work has been extracted from testcontainers#2202 and is related to testcontainers#2180. See the original PR for the full context and reasoning.

This will help with the documentation, since all examples will now have the module prefixes.
Minivera added a commit to Minivera/testcontainers-go that referenced this issue Feb 28, 2024
This work has been extracted from testcontainers#2202 and is related to testcontainers#2180. See the original PR for the full context and reasoning.

This will help with the documentation, since all examples will now have the module prefixes.
Minivera added a commit to Minivera/testcontainers-go that referenced this issue Feb 28, 2024
This work has been extracted from testcontainers#2202 and is related to testcontainers#2180. See the original PR for the full context and reasoning.

This will help with the documentation, since all examples will now have the module prefixes.
mdelapenya pushed a commit that referenced this issue Mar 1, 2024
* Move the file and mounts tests into a test package

This work has been extracted from #2202 and is related to #2180. See the original PR for the full context and reasoning.

This will help with the documentation, since all examples will now have the module prefixes.

* Rename the utils file
mdelapenya pushed a commit that referenced this issue Mar 12, 2024
* Move the container and config tests into a test package

This work has been extracted from #2202 and is related to #2180. See the original PR for the full context and reasoning.

* Rename the utils file

* Remove some unused code
Minivera added a commit to Minivera/testcontainers-go that referenced this issue Mar 18, 2024
This work has been extracted from testcontainers#2202 and is related to testcontainers#2180. See the original PR for the full context and reasoning. This PR in particular moves all the simpler tests in one go, or adds a comment to any remaining tests that would not make sense to move (or could not be moved without exposing a lot of variables).

This will help with the documentation, since all examples will now have the module prefixes.
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
2 participants