模拟 BigQuery 进行集成测试

huangapple go评论67阅读模式
英文:

Mocking Bigquery for integration test

问题

我正在使用https://github.com/googleapis/google-cloud-go与GCP Bigquery进行交互,以获取一些数据。

我想为我的代码编写一些测试。对于单元测试来说很容易,因为我可以模拟我的存储库(数据层)并返回我期望的结果。

我正在寻找如何编写Golang中GCP Bigquery的集成测试。如果只是基本的HTTP,我可以编写一个httptest服务器并返回一些虚拟(假的)数据。但是这个库使用gRPC与GCP Bigquery进行通信。

我想知道如何为GCP Bigquery编写集成测试。

让我们以最简单的方式进行,只提供“查询数据集中的表并读取数据”的集成部分。

英文:

I'm using https://github.com/googleapis/google-cloud-go to interact with GCP Bigquery to fetch some data.

I want to write some tests for my code. for the unit testing, it's easy because I can mock my repository ( data layer) and return what I expected for.

I'm looking for writing an integration test, if it was just basic HTTP I could write a httptest server and return some dummy ( fake) data. but this library is using gRPC to communicate with GCP Bigquery.

I'm wondering how I can write an integration test for GCP Bigquery in Golang.

let's keep it in the simplest way and just provide the integration part for Query a table in a dataset and read data.

答案1

得分: 4

你可以在本地运行依赖项。阅读:Google BigQuery的Docker容器

你可以编写脚本,在Docker容器中运行测试和依赖项(BigQuery)

如果你不想使用Docker运行测试,你可以使用bigquery-emulator

或者只是模拟它
将你的存储库(数据层)作为接口发送到你的HTTP服务器
然后你可以使用模拟运行测试

英文:

You can run dependency locally. Read :
Docker container for Google BigQuery

You can write script for running tests and dependencies(BigQuery) in docker container

If you dont want to run test using docker you can use bigquery-emulator

Or just mock it
Send your repository(data layer) as interface to your http server
And then you run test use mock

huangapple
  • 本文由 发表于 2022年12月22日 00:04:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/74878734.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定