fake.go 3.2 KB

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