fake.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. "errors"
  16. "github.com/aws/aws-sdk-go-v2/service/ssm"
  17. "github.com/google/go-cmp/cmp"
  18. "github.com/google/go-cmp/cmp/cmpopts"
  19. )
  20. // Client implements the aws parameterstore interface.
  21. type Client struct {
  22. GetParameterFn GetParameterFn
  23. GetParametersByPathFn GetParametersByPathFn
  24. PutParameterFn PutParameterFn
  25. PutParameterCalledN int
  26. PutParameterFnCalledWith [][]*ssm.PutParameterInput
  27. DeleteParameterFn DeleteParameterFn
  28. DescribeParametersFn DescribeParametersFn
  29. ListTagsForResourceFn ListTagsForResourceFn
  30. }
  31. type GetParameterFn func(context.Context, *ssm.GetParameterInput, ...func(*ssm.Options)) (*ssm.GetParameterOutput, error)
  32. type GetParametersByPathFn func(context.Context, *ssm.GetParametersByPathInput, ...func(*ssm.Options)) (*ssm.GetParametersByPathOutput, error)
  33. type PutParameterFn func(context.Context, *ssm.PutParameterInput, ...func(*ssm.Options)) (*ssm.PutParameterOutput, error)
  34. type DescribeParametersFn func(context.Context, *ssm.DescribeParametersInput, ...func(*ssm.Options)) (*ssm.DescribeParametersOutput, error)
  35. type ListTagsForResourceFn func(context.Context, *ssm.ListTagsForResourceInput, ...func(*ssm.Options)) (*ssm.ListTagsForResourceOutput, error)
  36. type DeleteParameterFn func(ctx context.Context, input *ssm.DeleteParameterInput, opts ...func(*ssm.Options)) (*ssm.DeleteParameterOutput, error)
  37. func (sm *Client) ListTagsForResource(ctx context.Context, input *ssm.ListTagsForResourceInput, options ...func(*ssm.Options)) (*ssm.ListTagsForResourceOutput, error) {
  38. return sm.ListTagsForResourceFn(ctx, input, options...)
  39. }
  40. func NewListTagsForResourceFn(output *ssm.ListTagsForResourceOutput, err error) ListTagsForResourceFn {
  41. return func(context.Context, *ssm.ListTagsForResourceInput, ...func(*ssm.Options)) (*ssm.ListTagsForResourceOutput, error) {
  42. return output, err
  43. }
  44. }
  45. func (sm *Client) DeleteParameter(ctx context.Context, input *ssm.DeleteParameterInput, opts ...func(*ssm.Options)) (*ssm.DeleteParameterOutput, error) {
  46. return sm.DeleteParameterFn(ctx, input, opts...)
  47. }
  48. func NewDeleteParameterFn(output *ssm.DeleteParameterOutput, err error) DeleteParameterFn {
  49. return func(context.Context, *ssm.DeleteParameterInput, ...func(*ssm.Options)) (*ssm.DeleteParameterOutput, error) {
  50. return output, err
  51. }
  52. }
  53. func (sm *Client) GetParameter(ctx context.Context, input *ssm.GetParameterInput, options ...func(*ssm.Options)) (*ssm.GetParameterOutput, error) {
  54. return sm.GetParameterFn(ctx, input, options...)
  55. }
  56. func (sm *Client) GetParametersByPath(ctx context.Context, input *ssm.GetParametersByPathInput, options ...func(*ssm.Options)) (*ssm.GetParametersByPathOutput, error) {
  57. return sm.GetParametersByPathFn(ctx, input, options...)
  58. }
  59. func NewGetParameterFn(output *ssm.GetParameterOutput, err error) GetParameterFn {
  60. return func(context.Context, *ssm.GetParameterInput, ...func(*ssm.Options)) (*ssm.GetParameterOutput, error) {
  61. return output, err
  62. }
  63. }
  64. func (sm *Client) DescribeParameters(ctx context.Context, input *ssm.DescribeParametersInput, options ...func(*ssm.Options)) (*ssm.DescribeParametersOutput, error) {
  65. return sm.DescribeParametersFn(ctx, input, options...)
  66. }
  67. func NewDescribeParametersFn(output *ssm.DescribeParametersOutput, err error) DescribeParametersFn {
  68. return func(context.Context, *ssm.DescribeParametersInput, ...func(*ssm.Options)) (*ssm.DescribeParametersOutput, error) {
  69. return output, err
  70. }
  71. }
  72. func (sm *Client) PutParameter(ctx context.Context, input *ssm.PutParameterInput, options ...func(*ssm.Options)) (*ssm.PutParameterOutput, error) {
  73. sm.PutParameterCalledN++
  74. sm.PutParameterFnCalledWith = append(sm.PutParameterFnCalledWith, []*ssm.PutParameterInput{input})
  75. return sm.PutParameterFn(ctx, input, options...)
  76. }
  77. func NewPutParameterFn(output *ssm.PutParameterOutput, err error) PutParameterFn {
  78. return func(context.Context, *ssm.PutParameterInput, ...func(*ssm.Options)) (*ssm.PutParameterOutput, error) {
  79. return output, err
  80. }
  81. }
  82. func (sm *Client) WithValue(in *ssm.GetParameterInput, val *ssm.GetParameterOutput, err error) {
  83. sm.GetParameterFn = func(ctx context.Context, paramIn *ssm.GetParameterInput, options ...func(*ssm.Options)) (*ssm.GetParameterOutput, error) {
  84. if !cmp.Equal(paramIn, in, cmpopts.IgnoreUnexported(ssm.GetParameterInput{})) {
  85. return nil, errors.New("unexpected test argument")
  86. }
  87. return val, err
  88. }
  89. }