Azure / azure-sdk-for-go

This repository is for active development of the Azure SDK for Go. For consumers of the SDK we recommend visiting our public developer docs at:
https://docs.microsoft.com/azure/developer/go/
MIT License
1.59k stars 821 forks source link

How to easy fake cosmos client #19943

Open mingqishao opened 1 year ago

mingqishao commented 1 year ago

Feature Request

We are using azcosmos package to talk with CosmosDB. We are struggling with mock the cosmos client for unit test. I'm wonder if the azcosmos SDK could provide a easy way to mock.

I found a usefully example from Compute SDK as reference: https://github.com/Azure/azure-sdk-for-go/blob/fake_prototype/sdk/resourcemanager/compute/armcompute/README.md#fakes

ealsur commented 1 year ago

@mingqishao If the fake package allows the creation of the Transport then it should be also available for azcosmos.

The Options on client creation let you set the Transport.

Just saw that the fakes is only available for ARM Compute. I wonder if this needs to be created for all SDKs?

@jhendrixMSFT Are there any other recommendations for external users to mock the transport or the SDKs?

mingqishao commented 1 year ago

I found a internal package in SDK github.com/Azure/azure-sdk-for-go/sdk/internal/mock. That will be very useful for us if you can expose this package. That allow use to easily mock any service's client.

andrew-lis commented 6 months ago

I don't want mocks. I want stubs for CosmosDb SDK Fake implementations like the other MS team did:

or remove sealed keywords so we can make these fakes/stub by over selves.