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

Have tests for kcctl #44

Closed
gunnarmorling opened this issue Aug 14, 2021 · 8 comments · Fixed by #144
Closed

Have tests for kcctl #44

gunnarmorling opened this issue Aug 14, 2021 · 8 comments · Fixed by #144

Comments

@gunnarmorling
Copy link
Collaborator

Currently, no tests exist for kcctl at all. We should add tests for the different commands, so to avoid regressions down the road. As part of this task, we need to

  • Understand how PicoCLI applications are tested; is their any guidance in their docs?
  • Set up the infrastructure for integration tests via Testcontainers; we'll need to start up ZooKeeper, Kafka, and Kafka Connect for testing kcctl; as inspiration or starting point, here's a Docker Compose file which shows the required components; as a test connector, the built-in file connector could probably be used
@SiddiqueAhmad
Copy link
Contributor

I setup the container resources class took help from debezium facing few issues, but we will do it

@karim-elngr
Copy link
Contributor

karim-elngr commented Aug 14, 2021

The picocli documentation provide some helpful insights into writing tests

@QuarkusTest
class PauseConnectorCommandTest {

    final PrintStream originalOut = System.out;
    final PrintStream originalErr = System.err;
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final ByteArrayOutputStream err = new ByteArrayOutputStream();

    @Inject
    CommandLine commandLine;

    @BeforeEach
    public void setUpStreams() {
        out.reset();
        err.reset();
        System.setOut(new PrintStream(out));
        System.setErr(new PrintStream(err));
    }

    @AfterEach
    public void restoreStreams() {
        System.setOut(originalOut);
        System.setErr(originalErr);
    }

    @Test
    void run() {

        String[] args = "pause connector connector-1".split(" ");

        commandLine.execute(args);

        assertEquals("", out.toString());
        assertEquals("", err.toString());
    }
}

@gunnarmorling
Copy link
Collaborator Author

Thanks, @karim-elngr, so essentially we'd just do assertions on the output stream we've set before. Makes sense. We can throw AssertJ into the mix for more expressive assertions.

@SiddiqueAhmad, ok, excellent. Seems the way forward to having some first integration tests is pretty clear then.

@karim-elngr
Copy link
Contributor

I think this is worth mentioning that SDK man uses a very interesting BDD approach for testing, I wonder if there is a common approach to test cli tools

https://github.com/sdkman/sdkman-cli/blob/master/src/test/resources/features/java_installation.feature

@gunnarmorling
Copy link
Collaborator Author

Hey @karim-elngr, out curiosity, did you have any chance to make some progress here?

@karim-elngr
Copy link
Contributor

Hi @gunnarmorling I was taking some time off before starting my new role, I will try to get some progress going next week!

@SiddiqueAhmad
Copy link
Contributor

hi @karim-elngr I tried the code snippet above but I am losing context when command is being executed, #85 have more detail

gunnarmorling pushed a commit that referenced this issue Jan 22, 2022
- Add helper method for registering a test connector using Debezium
Container
- Add lifecycle hook for injecting a command context into subclasses
containing the desired command instance to reduce boilerplate
- Add Quarkus Test Profile
gunnarmorling added a commit that referenced this issue Jan 22, 2022
@gunnarmorling gunnarmorling mentioned this issue Jan 22, 2022
Merged
gunnarmorling added a commit that referenced this issue Jan 22, 2022
gunnarmorling added a commit that referenced this issue Jan 22, 2022
gunnarmorling added a commit that referenced this issue Jan 22, 2022
gunnarmorling pushed a commit that referenced this issue Jan 22, 2022
- Add helper method for registering a test connector using Debezium
Container
- Add lifecycle hook for injecting a command context into subclasses
containing the desired command instance to reduce boilerplate
- Add Quarkus Test Profile
@gunnarmorling
Copy link
Collaborator Author

That's done now thanks to a heroic effort by @iabudiab 🎉 .

gunnarmorling added a commit that referenced this issue Jan 22, 2022
Docker isn't available in that environment.
gunnarmorling added a commit that referenced this issue Jan 22, 2022
Docker isn't available in that environment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants