Mocking strategy for external API libraries: google/go-github example

Written by
Link to Post

Hello everyone. Fairly new to Go here.

I read lot of content about mocking strategies, but I still don’t get how to mock external-provided libraries. For example, I am writing an application that calls GitHub API v3 using the well-known I want to mock calls to the library in order to test my business logic. Here’s my function:

import ( // ... "" ) func DoSomething(...) (result Result, err error) { ... fileContents, _, _, err := github.Repositories.GetContents(ctx, owner, repo, filename, nil) if err != nil { log.Fatal(err) } // Do something with fileContents return result, err } 

I want to test the return value of DoSomething by mocking github.Repositories.GetContents.

submitted by /u/-fly-
[link] [comments]

Article Tags:
· ·
Article Categories:

Leave a Reply