From c3c5b4543a2f22364328eaa1c8af8a88992ef0c9 Mon Sep 17 00:00:00 2001 From: thijsheijden <hi@thijsheijden.nl> Date: Mon, 19 Apr 2021 20:17:16 +0200 Subject: [PATCH] Added mock database request service --- internal/usecases/request/mock/mockrequest.go | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 internal/usecases/request/mock/mockrequest.go diff --git a/internal/usecases/request/mock/mockrequest.go b/internal/usecases/request/mock/mockrequest.go new file mode 100644 index 0000000..758a0ea --- /dev/null +++ b/internal/usecases/request/mock/mockrequest.go @@ -0,0 +1,33 @@ +package mockrequest + +import ( + "errors" + "query-service/internal/entity" +) + +// A Service implements the request usecases (mock) +type Service struct { + throwError bool +} + +// NewService creates a new service (mock) +func NewService() *Service { + return &Service{ + throwError: false, + } +} + +// SendAQLQuery sends the query to arangoDB and parses the result (mock) +func (s *Service) SendAQLQuery(query string) (*map[string][]entity.Document, error) { + mockResult := make(map[string][]entity.Document) + + if !s.throwError { + return &mockResult, nil + } + return nil, errors.New("Database error") +} + +// ToggleError decides whether the convert function throws an error +func (s *Service) ToggleError() { + s.throwError = !s.throwError +} -- GitLab