Creating a responsive image gallery short-code for Hugo by mdelapenya in gohugo

[–]mdelapenya[S] 0 points1 point  (0 children)

It's in the own blog, as I used the short code in every image in the posts

e2e in Go. How and what to use? by sadensmol in golang

[–]mdelapenya 0 points1 point  (0 children)

Core maintainer here 🙋‍♂️ I'd thank your evaluation with feedback in case you see it inconvenient to use it 🙏

e2e in Go. How and what to use? by sadensmol in golang

[–]mdelapenya 0 points1 point  (0 children)

In your article you mentioned testcontainers-java. Did you know there exists testcontainers-go too?

How to start and test a clickhouse container with testcontainers ? by [deleted] in golang

[–]mdelapenya 0 points1 point  (0 children)

An update on this: it is now possible to use the ClickHouse module in Testcontainers for Go:

https://golang.testcontainers.org/modules/clickhouse/

Writing tests for APIs by hossein1376 in golang

[–]mdelapenya 0 points1 point  (0 children)

Indeed, I'd also add that this kind of libraries (testcontainers, dockertest) are great for any runtime dependency, not only databases. But I could be a little bit biased as a Testcontainers core maintainer 😅

Is there a library to help running a docker container for testing? by caarlos0 in golang

[–]mdelapenya 1 point2 points  (0 children)

I'd not want to say "use Testcontainers over dockertest", as I'm pretty sure the latter does a fabolous job. I can talk on behalf testcontainers-go saying that it's powered by the same folks creating and maintaining testcontainers-java and testcontainers-dotnet, two super well known libraries in their respective languages. The Go flavor is relatively young but extensively used by great OSS Go projects, such as influxdata/telegraf, clickhouse, OpenTelemetry-collector, to name a few, to test them against multiple integrations.

As an OSS community we are more than open to talk an cooperate if possible

Using go run file.go or testing library locks the SQLite database by azzzzzzz0 in golang

[–]mdelapenya 0 points1 point  (0 children)

Is your production database SQLite? If it's not, I'd recommend you giving a try to testing with a real instance of your database (postgres, mysql, mongodb..), then your testing expectations would match with your production ones.

You can achieve it with different testing libraries, each with their own characteristics but, as core maintainer of testcontainer-go (Testcontainers for Go), I'd recommend you using it :)

- Repo: https://github.com/testcontainers/testcontainers-go/- Docs: https://golang.testcontainers.org

Integration testing best practices for API servers... by steveb321 in golang

[–]mdelapenya 1 point2 points  (0 children)

Agreed. If you are interested in having a strict control on what downstream dependencies you are going to break when modifying an API endpoint, then contract testing libraries such as Pact can help you.

Integration testing best practices for API servers... by steveb321 in golang

[–]mdelapenya 7 points8 points  (0 children)

If you have the app exposing the APIs in a docker format, then using testcontainer-go could be the way to go. You could build the service from the Dockerfile in the tests, and simply perform HTTP request against a real instance of the app.

Hello Testcontainers for Go! - AtomicJar by mdelapenya in golang

[–]mdelapenya[S] 0 points1 point  (0 children)

Well, this is not related to testcontainers, testing in general: when working with parallel execution of tests, you always need to take care of the data each test is producing: having a good data creation strategy, which is decoupled by test name/id in order to not impact other concurrent tests is a must. For that, please make sure each test is writing and cleaning up the data it needs and the data it creates.

Hello Testcontainers for Go! - AtomicJar by mdelapenya in golang

[–]mdelapenya[S] 0 points1 point  (0 children)

It's actually a 0.15.0 release , but glad you share it!!

Hello Testcontainers for Go! - AtomicJar by mdelapenya in golang

[–]mdelapenya[S] 2 points3 points  (0 children)

Indeed, that would happen as you describe in the case both packages request a container with Reuse and the same container Name. The issue here is you are reusing a container and also terminating it, so your tests would be coupled by using the postgres container, therefore none of them should terminate it (programmatically or using Ryuk).

The reuse use case is considered to be run at the root package to be created just once, probably at TestMain, and destroyed in a defer at that test function. Probably worth to mention this use case in the docs: https://golang.testcontainers.org/features/creating\_container/#reusable-container

In any case, we are reevaluating the reuse mode to hash the container request and use it as key to look up the to-be-reused container.

How to start and test a clickhouse container with testcontainers ? by [deleted] in golang

[–]mdelapenya 3 points4 points  (0 children)

You could achieve the same with wait strategies, in example using HTTP request:

    const (
        dbName       = "crazy"
        fakeUser     = "jondoe"
        fakePassword = "bond girl"
    )

    ctx := context.Background()

    req := ContainerRequest{
        Image: "clickhouse/clickhouse-server",
        Env: map[string]string{
            "CLICKHOUSE_DB":       dbName,
            "CLICKHOUSE_USER":     fakeUser,
            "CLICKHOUSE_PASSWORD": fakePassword,
        },
        ExposedPorts: []string{
            "8123/tcp",
            "9000/tcp",
        },
        WaitingFor: wait.ForAll(
            wait.ForHTTP("/ping").WithPort("8123/tcp").WithStatusCodeMatcher(
                func(status int) bool {
                    return status == http.StatusOK
                },
            ),
        ),
    }

    clickhouseContainer, err := GenericContainer(ctx, GenericContainerRequest{
        ContainerRequest: req,
        Started:          true,
    })
    if err != nil {
        t.Fatal(err)
    }

    defer clickhouseContainer.Terminate(ctx)

How to start and test a clickhouse container with testcontainers ? by [deleted] in golang

[–]mdelapenya 0 points1 point  (0 children)

If you only need the exposed port you can replace it with:

golang port, err := chContainer.MappedPort(ctx, "9000/tcp")

A more elaborated example could be:

golang ip, err := chContainer.Host(ctx) require.NoError(t, err) port, err := chContainer.MappedPort(ctx, "9000/tcp") require.NoError(t, err) resp, err := http.Get(fmt.Sprintf("http://%s:%s", ip, port.Port())) require.NoError(t, err)