dajudge/kindcontainer

JUnit5 Support

Closed this issue · 7 comments

Hey, I'm wondering if there are any plans from you side to support JUnit 5. Whenever I try to start a test which includes your container JUnit complains about not finding any tests. From my experience this related to the mixing of JUnit 5 and JUnit 4 stuff.

Best regards and thanks for your work, it looks relay intressting

JUnit 5 integration is provided by testcontainers, the underlying framework used in kindcontainer. Here's their documentation on how to use it w/ JUnit 5: https://www.testcontainers.org/test_framework_integration/junit_5/

I just gave it a quick spin w/ JUnit 5 and I had no problems whatsoever.

Let me know if you need further hints on how to get started!

Here's the example I hacked together: kindcontainer-junit5-example.zip

Thanks for providing an example, the api server works, but I can't get the KindContainer to run:

I changed your code as following:

package com.dajudge.kindcontainer.junit5;

import com.dajudge.kindcontainer.KindContainer;
import io.fabric8.kubernetes.client.KubernetesClient;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class SomeTest {

    public static KindContainer CONTAINER = new KindContainer();

    @BeforeAll
    static void beforeAll() {
        CONTAINER.start();
    }

    @Test
    void run_test() {
        try (final KubernetesClient client = CONTAINER.client()) {
            assertEquals(1, client.nodes().list().getItems().size());
        }
    }
}

Test Results - SomeTest.pdf

I just did a test-run with KindContainer() instead of ApiServerContainer() and it also worked nicely, so the issues you're facing are not related to JUnit 5.

From the logs you provided I can see that apparently during the cluster startup the kubelet cannot be reached. If you could tell me a bit more about your setup that might give me some more hints on possible causes? Apart from that I'm a bit lost on what might possible cause this issue on your setup tbh.

Concerning your example (but unrelated to the issues you're experiencing) you're basically not using the JUnit integration of testcontainer and opt for manual life cycle control. While this is perfectly fine your code does not clean up the running container after the test. That's not a big deal since Ryuk will take care of shutting down the running containers after your test ends, but you should generally dispose of the created KindContainer() in a @AfterAll method if you're going that route.

I thought I would keep you updated, after figuring out the main problem source for me. Now, it works for me as well. It turned out, because I use Linux with btrfs, my main disk is not under /dev/something, it is under /dev/mapper/something.
It therefore always failed to mount certain dirs but didn't error out. Such a pain in the ass. I noticed when I tried to use k3d and found all sorts of different weird error messages. This lead me to this faq.

Luckily for me, it seems to have been fixed in kind, now it seems to just work fine.

This sounds a lot like #6. I'd be somewhat interested in a quick and easy way to reproduce it...

Yeah sounds very similar. To be honest I don't know why and at which exact point it started working.
I remember trying to use kind cli, which failed with a similar error as in your mentioned issue. But now not only kind works as expected without any hick ups, the provided demo project of yours works just fine as well.
So I figured at some point they eventually fixed the issue, for me at least.
I see still a lot of GitHub issues regarding btrfs errors in kind repo.