fake.go 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. listSecretsWithContext func(ctx context.Context, listSecretsOptions *sm.ListSecretsOptions) (result *sm.SecretMetadataPaginatedCollection, 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. ListSecretsOptions *sm.ListSecretsOptions
  31. ListSecretsOutput *sm.SecretMetadataPaginatedCollection
  32. ListSecretsErr error
  33. GetSecretByNameOptions *sm.GetSecretByNameTypeOptions
  34. GetSecretByNameOutput sm.SecretIntf
  35. GetSecretByNameErr error
  36. }
  37. func (mc *IBMMockClient) GetSecretWithContext(ctx context.Context, getSecretOptions *sm.GetSecretOptions) (result sm.SecretIntf, response *core.DetailedResponse, err error) {
  38. return mc.getSecretWithContext(ctx, getSecretOptions)
  39. }
  40. func (mc *IBMMockClient) ListSecretsWithContext(ctx context.Context, listSecretsOptions *sm.ListSecretsOptions) (result *sm.SecretMetadataPaginatedCollection, response *core.DetailedResponse, err error) {
  41. return mc.listSecretsWithContext(ctx, listSecretsOptions)
  42. }
  43. func (mc *IBMMockClient) GetSecretByNameTypeWithContext(ctx context.Context, getSecretByNameTypeOptions *sm.GetSecretByNameTypeOptions) (result sm.SecretIntf, response *core.DetailedResponse, err error) {
  44. return mc.getSecretByNameTypeWithContext(ctx, getSecretByNameTypeOptions)
  45. }
  46. func (mc *IBMMockClient) WithValue(params IBMMockClientParams) {
  47. if mc != nil {
  48. mc.getSecretWithContext = func(ctx context.Context, paramReq *sm.GetSecretOptions) (sm.SecretIntf, *core.DetailedResponse, error) {
  49. // type secretmanagerpb.AccessSecretVersionRequest contains unexported fields
  50. // use cmpopts.IgnoreUnexported to ignore all the unexported fields in the cmp.
  51. if !cmp.Equal(paramReq, params.GetSecretOptions, cmpopts.IgnoreUnexported(sm.Secret{})) {
  52. return nil, nil, fmt.Errorf("unexpected test argument for GetSecret: %s, %s", *paramReq.ID, *params.GetSecretOptions.ID)
  53. }
  54. return params.GetSecretOutput, nil, params.GetSecretErr
  55. }
  56. mc.listSecretsWithContext = func(ctx context.Context, paramReq *sm.ListSecretsOptions) (result *sm.SecretMetadataPaginatedCollection, response *core.DetailedResponse, err error) {
  57. // type secretmanagerpb.AccessSecretVersionRequest contains unexported fields
  58. // use cmpopts.IgnoreUnexported to ignore all the unexported fields in the cmp.
  59. if !cmp.Equal(paramReq, params.ListSecretsOptions, cmpopts.IgnoreUnexported(sm.SecretMetadataPaginatedCollection{})) {
  60. return nil, nil, fmt.Errorf("unexpected test argument for ListSecrets: %s, %s", *paramReq.Search, *params.ListSecretsOptions.Search)
  61. }
  62. return params.ListSecretsOutput, nil, params.ListSecretsErr
  63. }
  64. mc.getSecretByNameTypeWithContext = func(ctx context.Context, paramReq *sm.GetSecretByNameTypeOptions) (sm.SecretIntf, *core.DetailedResponse, error) {
  65. // type secretmanagerpb.AccessSecretVersionRequest contains unexported fields
  66. // use cmpopts.IgnoreUnexported to ignore all the unexported fields in the cmp.
  67. if !cmp.Equal(paramReq, params.GetSecretByNameOptions, cmpopts.IgnoreUnexported(sm.Secret{})) {
  68. return nil, nil, fmt.Errorf("unexpected test argument for GetSecretByNameType: %s, %s", *paramReq.Name, *params.GetSecretByNameOptions.Name)
  69. }
  70. return params.GetSecretByNameOutput, nil, params.GetSecretByNameErr
  71. }
  72. }
  73. }