flow-cli icon indicating copy to clipboard operation
flow-cli copied to clipboard

Test the commands layer

Open devbugging opened this issue 4 years ago • 2 comments

Issue To Be Solved

The command layer: https://github.com/onflow/flow-cli/tree/master/internal is lacking tests which has lead to multiple bugs with typos etc because it requires manual testing to detect that.

Suggest A Solution

Write tests that execute functions in the command layer (functions were extracted with the purpose of testability).

Transaction example: Test for send function here https://github.com/onflow/flow-cli/blob/master/internal/transactions/send.go#L55 Use mock ReaderWriter with afero mock loader to mock file loading like done here: https://github.com/onflow/flow-cli/blob/master/pkg/flowkit/config/loader_test.go#L88-L89 Test returned results in different formats.

devbugging avatar Jul 21 '21 09:07 devbugging

@sideninja For comparing the console print outputs of commands for testing, I was thinking about using a 2 pointer approach that compares equivalence of non-format characters (ie. newlines, tabs and spaces). However this approach totally disregards formatting so I'm not too sure of how viable this is, however I have some ideas of how we can consider formatting when checking, but what are your thoughts on this approach?

neil-ptr avatar Jul 29 '22 22:07 neil-ptr

I would say that once we have the service layer mocked out you can to an exact string match, since the result from the service layer will be predictable you can also exactly predict the output in different formats. If a formating changes (like adding a new line) then it's ok for the test to also break and require being updated.

devbugging avatar Aug 01 '22 09:08 devbugging