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

Split CLI and GRPC API tests #308

Closed
CMCDragonkai opened this issue Dec 20, 2021 · 4 comments · Fixed by #311
Closed

Split CLI and GRPC API tests #308

CMCDragonkai opened this issue Dec 20, 2021 · 4 comments · Fixed by #311
Assignees
Labels
development Standard development

Comments

@CMCDragonkai
Copy link
Member

CMCDragonkai commented Dec 20, 2021

Specification

It's time to split up the test modules for these areas, this will our test performance, and give us understanding of the test coverage of all our API behaviour:

  • tests/bin
  • tests/agent
  • tests/client

For tests/bin, each command can have its own test. Look at tests/bin/agent as a template for what to do. Right now all the other commands are single test modules in their own directory like tests/bin/identities/identities.test.ts. These should all be split up into individual commands. Note that most of the tests should be using the shared global agent. However some tests may be independent. This is where you can use the nested describe pattern as demonstrated in tests/bin/agent/status.test.ts.

Some tips:

  • Use the global shared agent
  • Use module mocking for prompting
  • Use the correct pkExec, pkStdio, pkSpawn, pkExpect utility
  • Use 1 nested describe at the bottom in case there is a need to use a the global shared agent and also have independent tests
  • Make sure to revert all side effects in the global shared agent! In every test!

We may optimise it further when realising that some tests can just use their own agent instead of sharing the agent. This is because by using the global keypair, starting agents is really fast now. This will probably need to be used in the nodes commands anyway.

For tests/agent and tests/client, this is about the GRPC API. We have now split up each RPC handler into their own file, this allows much more isolated and specific unit testing of each handler. Refer to tests/client/service/agentStop.test.ts as the template for each handler test. All rpc*.test.ts should be converted appropriately. Refer to #249 when you have questions or discussions about API design. This is just about splitting the tests up, however we may find we can fix things up regarding the API as this issue is tackled.

Additional context

Tasks

  1. Split up tests/bin
  2. Split up tests/client/service and refer to src/client/service and tests/client/service/agentStop.test.ts
  3. Split up tests/agent/service and refer to src/agent/service
  4. Check for other API conformance/design issues, such as error handling.
@CMCDragonkai
Copy link
Member Author

Should also revert any cases where beforeEach and afterEach is being used to control the lifecycle of the unit under test. The lifecycle of the unit under test should always be in each individual test.

@CMCDragonkai
Copy link
Member Author

Also wherever LogLevel is used, it should be WARN by default. Use ag to search.

@CMCDragonkai
Copy link
Member Author

CMCDragonkai commented Dec 20, 2021

Once tests are split up in the service. Most tests of GRPCClientClient.test.ts and GRPCClientAgent.test.ts can be removed, and they can just focus on the construction of the client object itself. For example the can get status test can be its own agentStatus.test.ts.

@CMCDragonkai
Copy link
Member Author

This should only be done on top of #292. Either that gets merged into master first, or any PRs has to be done on top of it as a stacked PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Standard development
Development

Successfully merging a pull request may close this issue.

2 participants