fake.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 ksm "github.com/keeper-security/secrets-manager-go/core"
  15. type MockKeeperClient struct {
  16. GetSecretsFn func([]string) ([]*ksm.Record, error)
  17. GetSecretByTitleFn func(recordTitle string) (*ksm.Record, error)
  18. GetSecretsByTitleFn func(recordTitle string) (records []*ksm.Record, err error)
  19. CreateSecretWithRecordDataFn func(recUID, folderUID string, recordData *ksm.RecordCreate) (string, error)
  20. DeleteSecretsFn func(recrecordUids []string) (map[string]string, error)
  21. SaveFn func(record *ksm.Record) error
  22. }
  23. type GetSecretsMockReturn struct {
  24. Secrets []*ksm.Record
  25. Err error
  26. }
  27. type GetSecretsByTitleMockReturn struct {
  28. Secret *ksm.Record
  29. Err error
  30. }
  31. type CreateSecretWithRecordDataMockReturn struct {
  32. ID string
  33. Err error
  34. }
  35. func (mc *MockKeeperClient) GetSecrets(filter []string) ([]*ksm.Record, error) {
  36. return mc.GetSecretsFn(filter)
  37. }
  38. func (mc *MockKeeperClient) GetSecretByTitle(recordTitle string) (*ksm.Record, error) {
  39. return mc.GetSecretByTitleFn(recordTitle)
  40. }
  41. func (mc *MockKeeperClient) GetSecretsByTitle(recordTitle string) (records []*ksm.Record, err error) {
  42. return mc.GetSecretsByTitleFn(recordTitle)
  43. }
  44. func (mc *MockKeeperClient) CreateSecretWithRecordData(recUID, folderUID string, recordData *ksm.RecordCreate) (string, error) {
  45. return mc.CreateSecretWithRecordDataFn(recUID, folderUID, recordData)
  46. }
  47. func (mc *MockKeeperClient) DeleteSecrets(recrecordUids []string) (map[string]string, error) {
  48. return mc.DeleteSecretsFn(recrecordUids)
  49. }
  50. func (mc *MockKeeperClient) Save(record *ksm.Record) error {
  51. return mc.SaveFn(record)
  52. }