all: Accept ServiceClient as an interface#3203
all: Accept ServiceClient as an interface#3203pierreprinetti wants to merge 2 commits intogophercloud:mainfrom
Conversation
879e4c8 to
d7a0053
Compare
|
How do you see client code using this? Here's an example of how we're using mocks in CAPO: https://github.com/kubernetes-sigs/cluster-api-provider-openstack/blob/852272197ad100fecd9cc7e95a77e88897812520/pkg/cloud/services/compute/instance_test.go#L82-L96 {
testName: "Return image ID when name given",
image: infrav1.ImageParam{
Filter: &infrav1.ImageFilter{
Name: ptr.To(imageName),
},
},
want: ptr.To(imageID),
expect: func(m *mock.MockImageClientMockRecorder) {
m.ListImages(images.ListOpts{Name: imageName}).Return(
[]images.Image{{ID: imageID, Name: imageName}},
nil)
},
wantErr: false,
},
With my 'gophercloud library user' hat on, what I'm trying to achieve here is:
I like that I can use gophercloud structs here. I'm asserting that the call uses an I could theoretically use the ServiceClient interface to mock my OpenStack calls, but this would take the gophercloud abstractions away from me. I would have to define my expected behaviours in terms of HTTP and raw json. I can imagine that we could fairly easily add a 'recording' mock ServiceClient interface which we create in the tests. My test might have a 'record' phase something like: mockServiceClient := MyMockServiceClient()
images.List(mockServiceClient ,images.ListOpts{Name: imageName})
... something with pages? ...I can imagine that MyMockServiceClient could record any resulting invocation, however complicated, which could be used later in the 'execute' phase of the test. I can't immediately think of a good way to use an interface like this to provide a return value, though. The return value I'm interested in is |
Have gophercloud.ServiceClient expose and EndpointURL method so that it can be used as a gophercloud.Client.
Allow client libraries to modify the behaviour of ServiceClient or mock calls to the OpenStack API.
d7a0053 to
c44b16b
Compare
|
Let's park this. |
Allow client libraries to modify the behaviour of ServiceClient or mock calls to the OpenStack API.
This change is targeted at
v3.