./images/avatar.png

How to mock Google BigQuery client in Golang

Whats the problem?

The official Google BigQuery packge for Golang is cloud.google.com/go/bigquery and when you create a client it returns a specific struct instead of an interface. This is a bit confusing, because even though it allow maintainers to add new methods to the bigquery client without worry that it would break consumers, it makes unit testing a bit more complex.

With a specific struct returned you can no longer simply sketch an object that fullfil the interface requirements or use mockery to do it for you. Suppose you have this toy example which prints the data from a table:

How to locally debug Gradescope Autograder



🤔



If you are trying to create a Gradescope Autograder then you have probably faced an issue how to properly test your docker image. Here is a solution which would create almost exact copy of the gradescope environment on your machine.

Docker file for testing

All you need is to create a second docker file which would emulate the gradescope image. Here it is:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
FROM YOUR_BASE_IMAGE_NAME

WORKDIR /autograder
COPY submission_metadata.json .

ADD test_submission.zip /autograder/submission/test_submission.zip
RUN mkdir /autograder/results
RUN unzip -d /autograder/submission ./submission/test_submission.zip

ENTRYPOINT ["/autograder/run_autograder"]

This docker file is creating an image which is based on your grading image (YOUR_BASE_IMAGE_NAME), includes dump submission metadata file (submission_metadata.json), unzip test submission from test_submission.zip and then run the entrypoint.