fake.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Copyright © The ESO Authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package fake
  14. import (
  15. "context"
  16. "fmt"
  17. "github.com/IBM/go-sdk-core/v5/core"
  18. sm "github.com/IBM/secrets-manager-go-sdk/v2/secretsmanagerv2"
  19. "github.com/google/go-cmp/cmp"
  20. "github.com/google/go-cmp/cmp/cmpopts"
  21. )
  22. type IBMMockClient struct {
  23. getSecretWithContext func(ctx context.Context, getSecretOptions *sm.GetSecretOptions) (result sm.SecretIntf, response *core.DetailedResponse, err error)
  24. getSecretByNameTypeWithContext func(ctx context.Context, getSecretByNameTypeOptions *sm.GetSecretByNameTypeOptions) (result sm.SecretIntf, response *core.DetailedResponse, err error)
  25. }
  26. type IBMMockClientParams struct {
  27. GetSecretOptions *sm.GetSecretOptions
  28. GetSecretOutput sm.SecretIntf
  29. GetSecretErr error
  30. GetSecretByNameOptions *sm.GetSecretByNameTypeOptions
  31. GetSecretByNameOutput sm.SecretIntf
  32. GetSecretByNameErr error
  33. }
  34. func (mc *IBMMockClient) GetSecretWithContext(ctx context.Context, getSecretOptions *sm.GetSecretOptions) (result sm.SecretIntf, response *core.DetailedResponse, err error) {
  35. return mc.getSecretWithContext(ctx, getSecretOptions)
  36. }
  37. func (mc *IBMMockClient) GetSecretByNameTypeWithContext(
  38. ctx context.Context,
  39. getSecretByNameTypeOptions *sm.GetSecretByNameTypeOptions,
  40. ) (result sm.SecretIntf, response *core.DetailedResponse, err error) {
  41. return mc.getSecretByNameTypeWithContext(ctx, getSecretByNameTypeOptions)
  42. }
  43. func (mc *IBMMockClient) WithValue(params IBMMockClientParams) {
  44. if mc != nil {
  45. mc.getSecretWithContext = func(ctx context.Context, paramReq *sm.GetSecretOptions) (sm.SecretIntf, *core.DetailedResponse, error) {
  46. // type secretmanagerpb.AccessSecretVersionRequest contains unexported fields
  47. // use cmpopts.IgnoreUnexported to ignore all the unexported fields in the cmp.
  48. if !cmp.Equal(paramReq, params.GetSecretOptions, cmpopts.IgnoreUnexported(sm.Secret{})) {
  49. return nil, nil, fmt.Errorf("unexpected test argument for GetSecret: %s, %s", *paramReq.ID, *params.GetSecretOptions.ID)
  50. }
  51. return params.GetSecretOutput, nil, params.GetSecretErr
  52. }
  53. mc.getSecretByNameTypeWithContext = func(ctx context.Context, paramReq *sm.GetSecretByNameTypeOptions) (sm.SecretIntf, *core.DetailedResponse, error) {
  54. // type secretmanagerpb.AccessSecretVersionRequest contains unexported fields
  55. // use cmpopts.IgnoreUnexported to ignore all the unexported fields in the cmp.
  56. if !cmp.Equal(paramReq, params.GetSecretByNameOptions, cmpopts.IgnoreUnexported(sm.Secret{})) {
  57. return nil, nil, fmt.Errorf("unexpected test argument for GetSecretByNameType: %s, %s", *paramReq.Name, *params.GetSecretByNameOptions.Name)
  58. }
  59. return params.GetSecretByNameOutput, nil, params.GetSecretByNameErr
  60. }
  61. }
  62. }