I need to mock a method for a Unit Test in golang

I have a function called NewSchema(ctx contractapi.TransactionContextInterface, groupName string, schemaName string, schemaText string), that calls a different function called SubmittingIdentityHasOU(ctx, ‘random_string’). I am writing a Unit test for the NewSchema function.

I have been trying to mock the response of SubmittingIdentityHasOU so that it returns true or false depending on the case of my tests. However, it seems that everytime I try, the tests doesn’t call the mock of said function, but it calls the actual implementation in the main code, which obviously causes a lot of trouble.

I’d like to learn how can you mock the behaviour of the embedded functions so that you can easily tests the cases for the NewSchema function.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.