Repository: clouditor/clouditor
Pull request #430 (2021-12-20 11:33:55)

Harmonize gRPC calls
Create handle-functions for gRPC calls
- orchestrator.StoreAssessmentResult(s)
- evidenceStore.StoreEvidence(s)
- assessment.AssessEvidence(s)

codecov[bot]: # [Codecov](https://codecov.io/gh/clouditor/clouditor/pull/430?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) Report
> Merging [#430](https://codecov.io/gh/clouditor/clouditor/pull/430?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) (fba4479) into [main](https://codecov.io/gh/clouditor/clouditor/commit/679b5cbf1c959914caa0751e333e09f6c42b5a74?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) (679b5cb) will **increase** coverage by `0.48%`.
> The diff coverage is `89.74%`.

[![Impacted file tree graph](https://codecov.io/gh/clouditor/clouditor/pull/430/graphs/tree.svg?width=650&height=150&src=pr&token=syrXsw5LTX&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor)](https://codecov.io/gh/clouditor/clouditor/pull/430?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor)

```diff
@@            Coverage Diff             @@
##             main     #430      +/-   ##
==========================================
+ Coverage   68.73%   69.21%   +0.48%     
==========================================
  Files          39       39              
  Lines        3518     3531      +13     
==========================================
+ Hits         2418     2444      +26     
+ Misses        977      967      -10     
+ Partials      123      120       -3     
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `69.21% <89.74%> (+0.48%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/clouditor/clouditor/pull/430?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) | Coverage Δ | |
|---|---|---|
| [service/assessment/assessment.go](https://codecov.io/gh/clouditor/clouditor/pull/430/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9hc3Nlc3NtZW50L2Fzc2Vzc21lbnQuZ28=) | `91.66% <81.81%> (+5.42%)` | :arrow_up: |
| [service/evidence/evidence\_store.go](https://codecov.io/gh/clouditor/clouditor/pull/430/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9ldmlkZW5jZS9ldmlkZW5jZV9zdG9yZS5nbw==) | `94.20% <90.69%> (+7.53%)` | :arrow_up: |
| [service/orchestrator/orchestrator.go](https://codecov.io/gh/clouditor/clouditor/pull/430/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9vcmNoZXN0cmF0b3Ivb3JjaGVzdHJhdG9yLmdv) | `81.15% <91.66%> (+2.96%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/clouditor/clouditor/pull/430?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/clouditor/clouditor/pull/430?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor). Last update [679b5cb...fba4479](https://codecov.io/gh/clouditor/clouditor/pull/430?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor).

garuppel: I've changed the assessment.AssessEvidence(s)() and the orchestratore.StoreAssessmentResult(s)() as well. Now, the stream method calls the unary method.

Patch:
diff --git a/api/assessment/assessment.go b/api/assessment/assessment.go
index 2eceeda3..f3f2e617 100644
--- a/api/assessment/assessment.go
+++ b/api/assessment/assessment.go
@@ -27,6 +27,8 @@ package assessment
 
 import "errors"
 
+type ResultHookFunc func(result *AssessmentResult, err error)
+
 var (
 	ErrTimestampMissing                      = errors.New("timestamp in assessment result is missing")
 	ErrMetricIdMissing                       = errors.New("metric id in assessment result is missing")
diff --git a/api/evidence/evidence.go b/api/evidence/evidence.go
index 74ea81ac..8d1f2508 100644
--- a/api/evidence/evidence.go
+++ b/api/evidence/evidence.go
@@ -27,6 +27,8 @@ package evidence
 
 import "errors"
 
+type EvidenceHookFunc func(result *Evidence, err error)
+
 var (
 	ErrNotValidResource       = errors.New("resource in evidence is missing")
 	ErrResourceNotStruct      = errors.New("resource in evidence is not struct value")
diff --git a/service/assessment/assessment.go b/service/assessment/assessment.go
index 22bd1747..91d6c5c8 100644
--- a/service/assessment/assessment.go
+++ b/service/assessment/assessment.go
@@ -52,9 +52,9 @@ Service is an implementation of the Clouditor Assessment service. It should not
 NewService constructor should be used. It implements the AssessmentServer interface
 */
 type Service struct {
-	// resultHooks is a hook function that can be used if one wants to be
+	// resultHooks is a list of hook functions that can be used if one wants to be
 	// informed about each assessment result
-	resultHooks []func(result *assessment.AssessmentResult, err error)
+	resultHooks []assessment.ResultHookFunc
 
 	results map[string]*assessment.AssessmentResult
 	assessment.UnimplementedAssessmentServer
@@ -68,8 +68,21 @@ func NewService() *Service {
 
 // AssessEvidence is a method implementation of the assessment interface: It assesses a single evidence
 func (s Service) AssessEvidence(_ context.Context, req *assessment.AssessEvidenceRequest) (res *assessment.AssessEvidenceResponse, err error) {
-	err = s.handleEvidence(req.Evidence)
+	resourceId, err := req.Evidence.Validate()
+	if err != nil {
+		log.Errorf("Invalid evidence: %v", err)
+		newError := fmt.Errorf("invalid evidence: %w", err)
+
+		s.informHooks(nil, newError)
+
+		res = &assessment.AssessEvidenceResponse{
+			Status: false,
+		}
+
+		return res, status.Errorf(codes.InvalidArgument, "invalid req: %v", err)
+	}
 
+	err = s.handleEvidence(req.Evidence, resourceId)
 	if err != nil {
 		res = &assessment.AssessEvidenceResponse{
 			Status: false,
@@ -104,24 +117,19 @@ func (s Service) AssessEvidences(stream assessment.Assessment_AssessEvidencesSer
 			return err
 		}
 
-		err = s.handleEvidence(req.Evidence)
+		// Call AssessEvidence for assessing a single evidence
+		assessEvidencesReq := &assessment.AssessEvidenceRequest{
+			Evidence: req.Evidence,
+		}
+		_, err = s.AssessEvidence(context.Background(), assessEvidencesReq)
 		if err != nil {
-			return status.Errorf(codes.Internal, "error while handling evidence: %v", err)
+			return err
 		}
 	}
 }
 
-// handleEvidence is the common evidence assessment of AssessEvidence and AssessEvidences
-func (s Service) handleEvidence(evidence *evidence.Evidence) error {
-	resourceId, err := evidence.Validate()
-	if err != nil {
-		log.Errorf("Invalid evidence: %v", err)
-		newError := fmt.Errorf("invalid evidence: %w", err)
-
-		s.informHook(nil, newError)
-
-		return newError
-	}
+// handleEvidence is the helper method for the actual assessment used by AssessEvidence and AssessEvidences
+func (s Service) handleEvidence(evidence *evidence.Evidence, resourceId string) error {
 
 	log.Infof("Running evidence %s (%s) collected by %s at %v", evidence.Id, resourceId, evidence.ToolId, evidence.Timestamp)
 	log.Debugf("Evidence: %+v", evidence)
@@ -131,7 +139,7 @@ func (s Service) handleEvidence(evidence *evidence.Evidence) error {
 		log.Errorf("Could not evaluate evidence: %v", err)
 		newError := fmt.Errorf("could not evaluate evidence: %w", err)
 
-		s.informHook(nil, newError)
+		s.informHooks(nil, newError)
 
 		return newError
 	}
@@ -163,13 +171,14 @@ func (s Service) handleEvidence(evidence *evidence.Evidence) error {
 		// Just a little hack to quickly enable multiple results per resource
 		s.results[fmt.Sprintf("%s-%d", resourceId, i)] = result
 
-		s.informHook(result, nil)
+		s.informHooks(result, nil)
 	}
 
 	return nil
 }
 
-func (s Service) informHook(result *assessment.AssessmentResult, err error) {
+// informHooks informs the registered hook functions
+func (s Service) informHooks(result *assessment.AssessmentResult, err error) {
 	// Inform our hook, if we have any
 	if s.resultHooks != nil {
 		for _, hook := range s.resultHooks {
diff --git a/service/evidence/evidence_store.go b/service/evidence/evidence_store.go
index cf2d2521..c60ba7c5 100644
--- a/service/evidence/evidence_store.go
+++ b/service/evidence/evidence_store.go
@@ -19,8 +19,9 @@ type Service struct {
 	// Currently only in-memory
 	evidences map[string]*evidence.Evidence
 
-	// Hook
-	evidenceHook []func(result *evidence.Evidence, err error)
+	// evidenceHooks is a list of hook functions that can be used if one wants to be
+	// informed about each evidence
+	evidenceHooks []evidence.EvidenceHookFunc
 
 	evidence.UnimplementedEvidenceStoreServer
 }
@@ -38,16 +39,23 @@ func init() {
 // StoreEvidence is a method implementation of the evidenceServer interface: It receives an req and stores it
 func (s *Service) StoreEvidence(_ context.Context, req *evidence.StoreEvidenceRequest) (resp *evidence.StoreEvidenceResponse, err error) {
 
-	err = s.handleEvidence(req.GetEvidence())
-
+	_, err = req.Evidence.Validate()
 	if err != nil {
+		log.Errorf("Invalid evidence: %v", err)
+		newError := fmt.Errorf("invalid evidence: %w", err)
+
+		s.informHooks(nil, newError)
+
 		resp = &evidence.StoreEvidenceResponse{
 			Status: false,
 		}
 
-		return resp, status.Errorf(codes.Internal, "error while handling evidence: %v", err)
+		return resp, status.Errorf(codes.InvalidArgument, "invalid req: %v", err)
 	}
 
+	s.evidences[req.Evidence.Id] = req.Evidence
+	s.informHooks(req.Evidence, nil)
+
 	resp = &evidence.StoreEvidenceResponse{
 		Status: true,
 	}
@@ -72,32 +80,17 @@ func (s *Service) StoreEvidences(stream evidence.EvidenceStore_StoreEvidencesSer
 			return err
 		}
 
-		err = s.handleEvidence(req.GetEvidence())
+		// Call StoreEvidence() for storing a single evidence
+		evidenceRequest := &evidence.StoreEvidenceRequest{
+			Evidence: req.Evidence,
+		}
+		_, err = s.StoreEvidence(context.Background(), evidenceRequest)
 		if err != nil {
-			return status.Errorf(codes.Internal, "error while handling evidence: %v", err)
+			return err
 		}
 	}
 }
 
-func (s *Service) handleEvidence(e *evidence.Evidence) (err error) {
-
-	_, err = e.Validate()
-	if err != nil {
-		log.Errorf("Invalid evidence: %v", err)
-		newError := fmt.Errorf("invalid evidence: %w", err)
-
-		s.informHook(nil, newError)
-
-		return
-	}
-
-	s.evidences[e.Id] = e
-
-	s.informHook(e, nil)
-
-	return
-}
-
 // ListEvidences is a method implementation of the evidenceServer interface: It returns the evidences lying in the req storage
 func (s *Service) ListEvidences(_ context.Context, _ *evidence.ListEvidencesRequest) (*evidence.ListEvidencesResponse, error) {
 	var listOfEvidences []*evidence.Evidence
@@ -108,14 +101,14 @@ func (s *Service) ListEvidences(_ context.Context, _ *evidence.ListEvidencesRequ
 	return &evidence.ListEvidencesResponse{Evidences: listOfEvidences}, nil
 }
 
-func (s *Service) RegisterEvidenceHook(evidenceHook func(result *evidence.Evidence, err error)) {
-	s.evidenceHook = append(s.evidenceHook, evidenceHook)
+func (s *Service) RegisterEvidenceHook(evidenceHook evidence.EvidenceHookFunc) {
+	s.evidenceHooks = append(s.evidenceHooks, evidenceHook)
 }
 
-func (s Service) informHook(result *evidence.Evidence, err error) {
+func (s Service) informHooks(result *evidence.Evidence, err error) {
 	// Inform our hook, if we have any
-	if s.evidenceHook != nil {
-		for _, hook := range s.evidenceHook {
+	if s.evidenceHooks != nil {
+		for _, hook := range s.evidenceHooks {
 			go hook(result, err)
 		}
 	}
diff --git a/service/orchestrator/orchestrator.go b/service/orchestrator/orchestrator.go
index 1d318fb9..66452285 100644
--- a/service/orchestrator/orchestrator.go
+++ b/service/orchestrator/orchestrator.go
@@ -199,12 +199,21 @@ func (s *Service) StoreAssessmentResult(_ context.Context, req *orchestrator.Sto
 
 	resp = &orchestrator.StoreAssessmentResultResponse{}
 
-	err = s.handleResult(req.Result)
+	_, err = req.Result.Validate()
 
 	if err != nil {
-		return resp, status.Errorf(codes.InvalidArgument, "error while handling assessment result: %v", err)
+		log.Errorf("Invalid assessment result: %v", err)
+		newError := fmt.Errorf("invalid assessment result: %w", err)
+
+		s.informHook(nil, newError)
+
+		return resp, status.Errorf(codes.InvalidArgument, "invalid req: %v", err)
 	}
 
+	s.results[req.Result.Id] = req.Result
+
+	s.informHook(req.Result, nil)
+
 	return
 }
 
@@ -224,30 +233,17 @@ func (s *Service) StoreAssessmentResults(stream orchestrator.Orchestrator_StoreA
 			return err
 		}
 
-		err = s.handleResult(result)
-		if err != nil {
-			return status.Errorf(codes.Internal, "error while handling assessment result: %v", err)
+		// Call StoreAssessmentResult() for storing a single assessment
+		storeAssessmentResultReq := &orchestrator.StoreAssessmentResultRequest{
+			Result: result,
 		}
-	}
-
-}
-
-func (s Service) handleResult(result *assessment.AssessmentResult) (err error) {
-	_, err = result.Validate()
-	if err != nil {
-		log.Errorf("Invalid assessment result: %v", err)
-		newError := fmt.Errorf("invalid assessment result: %w", err)
 
-		s.informHook(nil, newError)
-
-		return
+		_, err = s.StoreAssessmentResult(context.Background(), storeAssessmentResultReq)
+		if err != nil {
+			return err
+		}
 	}
 
-	s.results[result.Id] = result
-
-	s.informHook(result, nil)
-
-	return
 }
 
 func (s *Service) RegisterAssessmentResultHook(hook func(result *assessment.AssessmentResult, err error)) {
@@ -262,36 +258,3 @@ func (s Service) informHook(result *assessment.AssessmentResult, err error) {
 		}
 	}
 }
-
-//// Tools
-//
-//// TODO Implement DeregisterAssessmentTool
-//func ( *Service) RegisterAssessmentTool (ctx context.Context, request *orchestrator.RegisterAssessmentToolRequest) (tool *orchestrator.AssessmentTool, err error) {
-//	// TBD
-//	return tool, err
-//}
-//
-//// TODO Implement UpdateAssessmentTool
-//func ( *Service) UpdateAssessmentTool (ctx context.Context, request *orchestrator.UpdateAssessmentToolRequest) (tool *orchestrator.AssessmentTool, err error) {
-//	// TBD
-//	return tool, err
-//}
-//
-//// TODO Implement DeregisterAssessmentTool
-//func ( *Service) DeregisterAssessmentTool (ctx context.Context, request *orchestrator.DeregisterAssessmentToolRequest) (nil, err error) {
-//	// TBD
-//	return nil, err
-//}
-//
-//
-//// TODO Implement ListAssessmentTools
-//func ( *Service) ListAssessmentTools (ctx context.Context, request *orchestrator.ListAssessmentToolsRequest) (tools *orchestrator.ListAssessmentToolsResponse, err error) {
-//	// TBD
-//	return tools, err
-//}
-//
-//// TODO Implement GetAssessmentTool
-//func ( *Service) GetAssessmentTool (ctx context.Context, request *orchestrator.GetAssessmentToolRequest) (tool *orchestrator.AssessmentTool, err error) {
-//	// TBD
-//	return tool, err
-//}


Test patch:
diff --git a/service/assessment/assessment_test.go b/service/assessment/assessment_test.go
index e5588d8c..ea10bb34 100644
--- a/service/assessment/assessment_test.go
+++ b/service/assessment/assessment_test.go
@@ -151,7 +151,7 @@ func TestAssessEvidence(t *testing.T) {
 
 func TestService_AssessEvidences(t *testing.T) {
 	type fields struct {
-		ResultHook                    []func(result *assessment.AssessmentResult, err error)
+		ResultHooks                   []assessment.ResultHookFunc
 		results                       map[string]*assessment.AssessmentResult
 		UnimplementedAssessmentServer assessment.UnimplementedAssessmentServer
 	}
@@ -191,7 +191,7 @@ func TestService_AssessEvidences(t *testing.T) {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			s := Service{
-				resultHooks:                   tt.fields.ResultHook,
+				resultHooks:                   tt.fields.ResultHooks,
 				results:                       tt.fields.results,
 				UnimplementedAssessmentServer: tt.fields.UnimplementedAssessmentServer,
 			}
@@ -204,7 +204,7 @@ func TestService_AssessEvidences(t *testing.T) {
 	}
 }
 
-func TestAssessmentResultHook(t *testing.T) {
+func TestAssessmentResultHooks(t *testing.T) {
 	var (
 		hookCallCounter = 0
 		// Service needs to outlive the lifetime of the hook function
@@ -244,9 +244,9 @@ func TestAssessmentResultHook(t *testing.T) {
 
 	// Check GRPC call
 	type args struct {
-		in0                 context.Context
-		evidence            *assessment.AssessEvidenceRequest
-		resultHookFunctions []func(assessmentResult *assessment.AssessmentResult, err error)
+		in0         context.Context
+		evidence    *assessment.AssessEvidenceRequest
+		resultHooks []assessment.ResultHookFunc
 	}
 	tests := []struct {
 		name     string
@@ -271,7 +271,7 @@ func TestAssessmentResultHook(t *testing.T) {
 							},
 						}, t),
 					}},
-				resultHookFunctions: []func(assessmentResult *assessment.AssessmentResult, err error){storeAssessmentResultToOrchestrator, firstHookFunction, secondHookFunction},
+				resultHooks: []assessment.ResultHookFunc{storeAssessmentResultToOrchestrator, firstHookFunction, secondHookFunction},
 			},
 			wantErr:  false,
 			wantResp: &assessment.AssessEvidenceResponse{Status: true},
@@ -283,7 +283,7 @@ func TestAssessmentResultHook(t *testing.T) {
 			hookCallCounter = 0
 			s := NewService()
 
-			for i, hookFunction := range tt.args.resultHookFunctions {
+			for i, hookFunction := range tt.args.resultHooks {
 				s.RegisterAssessmentResultHook(hookFunction)
 
 				// Check if hook is registered
@@ -310,7 +310,7 @@ func TestAssessmentResultHook(t *testing.T) {
 	}
 }
 
-func TestService_ListAssessmentResults(t *testing.T) {
+func TestListAssessmentResults(t *testing.T) {
 	s := NewService()
 	_, err := s.AssessEvidence(context.TODO(), &assessment.AssessEvidenceRequest{
 		Evidence: &evidence.Evidence{
diff --git a/service/discovery/discovery_test.go b/service/discovery/discovery_test.go
index 98c1a768..a34abc3c 100644
--- a/service/discovery/discovery_test.go
+++ b/service/discovery/discovery_test.go
@@ -325,62 +325,3 @@ func (mockIsCloudResource) HasType(_ string) bool {
 func (mockIsCloudResource) GetCreationTime() *time.Time {
 	return nil
 }
-
-//// ToDo: Adapt TestQuery at a later stage when we fully implement the standalone version
-//func TestQuery(t *testing.T) {
-//	var (
-//		discoverer discovery.Discoverer
-//		response   *discovery.QueryResponse
-//		err        error
-//	)
-//
-//	var ready = make(chan bool)
-//
-//	assessmentServer := standalone.NewAssessmentServer().(*service_assessment.Service)
-//	assessmentServer.resultHook = func(result *assessment.Result, err error) {
-//		if result.MetricId == 1 {
-//			assert.Nil(t, err)
-//			assert.NotNil(t, result)
-//
-//			assert.Equal(t, "some-id", result.ResourceId)
-//			assert.Equal(t, true, result.Compliant)
-//		}
-//
-//		ready <- true
-//	}
-//
-//	client := standalone.NewAssessmentClient()
-//
-//	service = service_discovery.NewService()
-//	service.AssessmentStream, _ = client.AssessEvidences(context.Background())
-//
-//	// use our mock discoverer
-//	discoverer = mockDiscoverer{}
-//
-//	// discover some resources
-//	service.StartDiscovery(discoverer)
-//
-//	// make the test wait for streaming evidence
-//	select {
-//	case <-ready:
-//		break
-//	case <-time.After(10 * time.Second):
-//		assert.Fail(t, "Timeout while waiting for evidence assessment result to be ready")
-//	}
-//
-//	// query them
-//	response, err = service.Query(context.Background(), &discovery.QueryRequest{
-//		// this should only result 1 resource, and not the compute resource
-//		FilteredType: "ObjectStorage",
-//	})
-//
-//	assert.Nil(t, err)
-//	assert.NotNil(t, response)
-//	assert.NotEmpty(t, response.Result.Values)
-//
-//	m := response.Result.Values[0].GetStructValue().AsMap()
-//
-//	assert.NotNil(t, m)
-//	assert.Equal(t, "some-id", m["id"])
-//	assert.Equal(t, "some-name", m["name"])
-//}
diff --git a/service/evidence/evidence_store_test.go b/service/evidence/evidence_store_test.go
index 093a7c28..6af618b3 100644
--- a/service/evidence/evidence_store_test.go
+++ b/service/evidence/evidence_store_test.go
@@ -57,18 +57,19 @@ func TestStoreEvidence(t *testing.T) {
 			name: "Store req to the map",
 			args: args{
 				in0: context.TODO(),
-				req: &evidence.StoreEvidenceRequest{Evidence: &evidence.Evidence{
-					Id:        "MockEvidenceId",
-					ServiceId: "MockServiceId",
-					ToolId:    "MockTool",
-					Timestamp: timestamppb.Now(),
-					Raw:       "",
-					Resource: toStruct(voc.VirtualMachine{
-						Compute: &voc.Compute{CloudResource: &voc.CloudResource{
-							ID: "mock-id",
-						}},
-					}, t),
-				}},
+				req: &evidence.StoreEvidenceRequest{
+					Evidence: &evidence.Evidence{
+						Id:        "MockEvidenceId",
+						ServiceId: "MockServiceId",
+						ToolId:    "MockTool",
+						Timestamp: timestamppb.Now(),
+						Raw:       "",
+						Resource: toStruct(voc.VirtualMachine{
+							Compute: &voc.Compute{CloudResource: &voc.CloudResource{
+								ID: "mock-id",
+							}},
+						}, t),
+					}},
 			},
 			wantErr:  false,
 			wantResp: &evidence.StoreEvidenceResponse{Status: true},
@@ -77,19 +78,20 @@ func TestStoreEvidence(t *testing.T) {
 			name: "Store an evidence without toolId to the map",
 			args: args{
 				in0: context.TODO(),
-				req: &evidence.StoreEvidenceRequest{Evidence: &evidence.Evidence{
-					Id:        "MockEvidenceId-1",
-					ServiceId: "MockServiceId-1",
-					Timestamp: timestamppb.Now(),
-					Raw:       "",
-					Resource: toStruct(voc.VirtualMachine{
-						Compute: &voc.Compute{
-							CloudResource: &voc.CloudResource{
-								ID: "mock-id-1",
+				req: &evidence.StoreEvidenceRequest{
+					Evidence: &evidence.Evidence{
+						Id:        "MockEvidenceId-1",
+						ServiceId: "MockServiceId-1",
+						Timestamp: timestamppb.Now(),
+						Raw:       "",
+						Resource: toStruct(voc.VirtualMachine{
+							Compute: &voc.Compute{
+								CloudResource: &voc.CloudResource{
+									ID: "mock-id-1",
+								},
 							},
-						},
-					}, t),
-				},
+						}, t),
+					},
 				},
 			},
 			wantErr: true,
@@ -194,12 +196,12 @@ func TestEvidenceHook(t *testing.T) {
 	service.RegisterEvidenceHook(secondHookFunction)
 
 	// Check if first hook is registered
-	funcName1 := runtime.FuncForPC(reflect.ValueOf(service.evidenceHook[0]).Pointer()).Name()
+	funcName1 := runtime.FuncForPC(reflect.ValueOf(service.evidenceHooks[0]).Pointer()).Name()
 	funcName2 := runtime.FuncForPC(reflect.ValueOf(firstHookFunction).Pointer()).Name()
 	assert.Equal(t, funcName1, funcName2)
 
 	// Check if second hook is registered
-	funcName1 = runtime.FuncForPC(reflect.ValueOf(service.evidenceHook[1]).Pointer()).Name()
+	funcName1 = runtime.FuncForPC(reflect.ValueOf(service.evidenceHooks[1]).Pointer()).Name()
 	funcName2 = runtime.FuncForPC(reflect.ValueOf(secondHookFunction).Pointer()).Name()
 	assert.Equal(t, funcName1, funcName2)