'GoLang how to test without static mock data

Good day!

How to test code written in Go, which decrypts payload from some API, which I can't change?

Static mock data is not actual, since there is a signature and expiration date inside.

Also have idea to write some API to retrieve fresh payload data, but writing API to test seems to be bad idea.

Can you share ideas to test method of decrypting?



Solution 1:[1]

You can try to create a program that consume such api and save different files.

“Golden files”

Then use it in tests.

Expiration is not a problem if you save the moment that you perform the first request and use it instead “time.Now()”

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tiago Peczenyj