Repository: clouditor/clouditor
Pull request #432 (2021-12-20 13:29:57)

Using same package for tests

codecov[bot]: # [Codecov](https://codecov.io/gh/clouditor/clouditor/pull/432?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) Report
> Merging [#432](https://codecov.io/gh/clouditor/clouditor/pull/432?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) (767c43c) 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 **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/clouditor/clouditor/pull/432/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/432?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor)

```diff
@@           Coverage Diff           @@
##             main     #432   +/-   ##
=======================================
  Coverage   68.73%   68.73%           
=======================================
  Files          39       39           
  Lines        3518     3518           
=======================================
  Hits         2418     2418           
  Misses        977      977           
  Partials      123      123           
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `68.73% <100.00%> (ø)` | |

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/432?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) | Coverage Δ | |
|---|---|---|
| [service/orchestrator/orchestrator.go](https://codecov.io/gh/clouditor/clouditor/pull/432/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9vcmNoZXN0cmF0b3Ivb3JjaGVzdHJhdG9yLmdv) | `78.19% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/clouditor/clouditor/pull/432?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/432?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor). Last update [679b5cb...767c43c](https://codecov.io/gh/clouditor/clouditor/pull/432?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).


Patch:
diff --git a/service/orchestrator/orchestrator.go b/service/orchestrator/orchestrator.go
index f5009ad8..d87661aa 100644
--- a/service/orchestrator/orchestrator.go
+++ b/service/orchestrator/orchestrator.go
@@ -61,7 +61,7 @@ type Service struct {
 	metricConfigurations map[string]map[string]*assessment.MetricConfiguration
 
 	// Currently only in-memory
-	Results map[string]*assessment.AssessmentResult
+	results map[string]*assessment.AssessmentResult
 
 	// Hook
 	AssessmentResultsHook []func(result *assessment.AssessmentResult, err error)
@@ -75,7 +75,7 @@ func init() {
 
 func NewService() *Service {
 	s := Service{
-		Results:              make(map[string]*assessment.AssessmentResult),
+		results:              make(map[string]*assessment.AssessmentResult),
 		metricConfigurations: make(map[string]map[string]*assessment.MetricConfiguration),
 	}
 
@@ -242,7 +242,7 @@ func (s Service) handleResult(result *assessment.AssessmentResult) error {
 		return newError
 	}
 
-	s.Results[result.Id] = result
+	s.results[result.Id] = result
 
 	// Inform our hook, if we have any
 	if s.AssessmentResultsHook != nil {


Test patch:
diff --git a/cli/commands/cloud/cloud_test.go b/cli/commands/cloud/cloud_test.go
index 9a9e37f2..7dc0e504 100644
--- a/cli/commands/cloud/cloud_test.go
+++ b/cli/commands/cloud/cloud_test.go
@@ -23,7 +23,7 @@
 //
 // This file is part of Clouditor Community Edition.
 
-package cloud_test
+package cloud
 
 import (
 	"bytes"
@@ -36,7 +36,6 @@ import (
 
 	"clouditor.io/clouditor/api/orchestrator"
 	"clouditor.io/clouditor/cli"
-	"clouditor.io/clouditor/cli/commands/cloud"
 	"clouditor.io/clouditor/cli/commands/login"
 	"clouditor.io/clouditor/persistence"
 	service_auth "clouditor.io/clouditor/service/auth"
@@ -104,7 +103,7 @@ func TestMain(m *testing.M) {
 }
 
 func TestNewCloudCommand(t *testing.T) {
-	cmd := cloud.NewCloudCommand()
+	cmd := NewCloudCommand()
 
 	assert.NotNil(t, cmd)
 	assert.True(t, cmd.HasSubCommands())
@@ -117,7 +116,7 @@ func TestRegisterCloudServiceCommand(t *testing.T) {
 
 	cli.Output = &b
 
-	cmd := cloud.NewRegisterCloudServiceCommand()
+	cmd := NewRegisterCloudServiceCommand()
 	err = cmd.RunE(nil, []string{"not_default"})
 
 	assert.Nil(t, err)
@@ -135,7 +134,7 @@ func TestListCloudServicesCommand(t *testing.T) {
 
 	cli.Output = &b
 
-	cmd := cloud.NewListCloudServicesCommand()
+	cmd := NewListCloudServicesCommand()
 	err = cmd.RunE(nil, []string{})
 
 	assert.Nil(t, err)
@@ -153,7 +152,7 @@ func TestGetCloudServiceCommand(t *testing.T) {
 
 	cli.Output = &b
 
-	cmd := cloud.NewGetCloudServiceComand()
+	cmd := NewGetCloudServiceComand()
 	err = cmd.RunE(nil, []string{target.Id})
 
 	assert.Nil(t, err)
@@ -171,7 +170,7 @@ func TestRemoveCloudServicesCommand(t *testing.T) {
 
 	cli.Output = &b
 
-	cmd := cloud.NewRemoveCloudServiceComand()
+	cmd := NewRemoveCloudServiceComand()
 	err = cmd.RunE(nil, []string{target.Id})
 
 	assert.Nil(t, err)
@@ -196,7 +195,7 @@ func TestUpdateCloudServiceCommand(t *testing.T) {
 	viper.Set("id", target.Id)
 	viper.Set("name", "not_default")
 
-	cmd := cloud.NewUpdateCloudServiceCommand()
+	cmd := NewUpdateCloudServiceCommand()
 	err = cmd.RunE(nil, []string{})
 
 	assert.Nil(t, err)
@@ -223,7 +222,7 @@ func TestGetMetricConfiguration(t *testing.T) {
 	assert.NotNil(t, target)
 	assert.Nil(t, err)
 
-	cmd := cloud.NewGetMetricConfigurationCommand()
+	cmd := NewGetMetricConfigurationCommand()
 	err = cmd.RunE(nil, []string{target.Id, "TransportEncryptionEnabled"})
 
 	assert.Nil(t, err)
diff --git a/cli/commands/login/login_test.go b/cli/commands/login/login_test.go
index fc0e7e1a..f98dcdb1 100644
--- a/cli/commands/login/login_test.go
+++ b/cli/commands/login/login_test.go
@@ -23,7 +23,7 @@
 //
 // This file is part of Clouditor Community Edition.
 
-package login_test
+package login
 
 import (
 	"fmt"
@@ -32,7 +32,6 @@ import (
 	"os"
 	"testing"
 
-	"clouditor.io/clouditor/cli/commands/login"
 	"clouditor.io/clouditor/persistence"
 	service_auth "clouditor.io/clouditor/service/auth"
 	"github.com/spf13/viper"
@@ -76,7 +75,7 @@ func TestLogin(t *testing.T) {
 	viper.Set("password", "clouditor")
 	viper.Set("session-directory", dir)
 
-	cmd := login.NewLoginCommand()
+	cmd := NewLoginCommand()
 	err = cmd.RunE(nil, []string{fmt.Sprintf("localhost:%d", sock.Addr().(*net.TCPAddr).Port)})
 	assert.Nil(t, err)
 }
diff --git a/cli/commands/metric/metric_test.go b/cli/commands/metric/metric_test.go
index fb6d9af6..42f42f49 100644
--- a/cli/commands/metric/metric_test.go
+++ b/cli/commands/metric/metric_test.go
@@ -23,7 +23,7 @@
 //
 // This file is part of Clouditor Community Edition.
 
-package metric_test
+package metric
 
 import (
 	"bytes"
@@ -36,7 +36,6 @@ import (
 	"clouditor.io/clouditor/api/orchestrator"
 	"clouditor.io/clouditor/cli"
 	"clouditor.io/clouditor/cli/commands/login"
-	"clouditor.io/clouditor/cli/commands/metric"
 	"clouditor.io/clouditor/persistence"
 	service_auth "clouditor.io/clouditor/service/auth"
 	service_orchestrator "clouditor.io/clouditor/service/orchestrator"
@@ -103,7 +102,7 @@ func TestListMetrics(t *testing.T) {
 
 	cli.Output = &b
 
-	cmd := metric.NewListMetricsCommand()
+	cmd := NewListMetricsCommand()
 	err = cmd.RunE(nil, []string{})
 
 	assert.Nil(t, err)
@@ -123,7 +122,7 @@ func TestGetMetric(t *testing.T) {
 
 	cli.Output = &b
 
-	cmd := metric.NewGetMetricCommand()
+	cmd := NewGetMetricCommand()
 	err = cmd.RunE(nil, []string{"TransportEncryptionEnabled"})
 
 	assert.Nil(t, err)
diff --git a/cli/commands/tool/tool_test.go b/cli/commands/tool/tool_test.go
index 296de8e5..f3ab3f65 100644
--- a/cli/commands/tool/tool_test.go
+++ b/cli/commands/tool/tool_test.go
@@ -23,7 +23,7 @@
 //
 // This file is part of Clouditor Community Edition.
 
-package tool_test
+package tool
 
 import (
 	"fmt"
@@ -34,7 +34,6 @@ import (
 
 	"clouditor.io/clouditor/api/orchestrator"
 	"clouditor.io/clouditor/cli/commands/login"
-	"clouditor.io/clouditor/cli/commands/tool"
 	"clouditor.io/clouditor/persistence"
 	service_auth "clouditor.io/clouditor/service/auth"
 	service_orchestrator "clouditor.io/clouditor/service/orchestrator"
@@ -96,7 +95,7 @@ func TestMain(m *testing.M) {
 func TestListTool(t *testing.T) {
 	var err error
 
-	cmd := tool.NewListToolsCommand()
+	cmd := NewListToolsCommand()
 	err = cmd.RunE(nil, []string{})
 
 	// unsupported for now
@@ -107,7 +106,7 @@ func TestListTool(t *testing.T) {
 func TestShowTool(t *testing.T) {
 	var err error
 
-	cmd := tool.NewShowToolCommand()
+	cmd := NewShowToolCommand()
 	err = cmd.RunE(nil, []string{"1"})
 
 	// unsupported for now
@@ -118,7 +117,7 @@ func TestShowTool(t *testing.T) {
 func TestUpdateTool(t *testing.T) {
 	var err error
 
-	cmd := tool.NewUpdateToolCommand()
+	cmd := NewUpdateToolCommand()
 	err = cmd.RunE(nil, []string{"1"})
 
 	// unsupported for now
@@ -129,7 +128,7 @@ func TestUpdateTool(t *testing.T) {
 func TestRegisterTool(t *testing.T) {
 	var err error
 
-	cmd := tool.NewRegisterToolCommand()
+	cmd := NewRegisterToolCommand()
 	err = cmd.RunE(nil, []string{})
 
 	// unsupported for now
@@ -140,7 +139,7 @@ func TestRegisterTool(t *testing.T) {
 func TestDeregisterTool(t *testing.T) {
 	var err error
 
-	cmd := tool.NewDeregisterToolCommand()
+	cmd := NewDeregisterToolCommand()
 	err = cmd.RunE(nil, []string{"1"})
 
 	// unsupported for now
diff --git a/cli/session_test.go b/cli/session_test.go
index 01f8076a..12ef3888 100644
--- a/cli/session_test.go
+++ b/cli/session_test.go
@@ -23,7 +23,7 @@
 //
 // This file is part of Clouditor Community Edition.
 
-package cli_test
+package cli
 
 import (
 	"context"
@@ -35,7 +35,6 @@ import (
 	"testing"
 
 	"clouditor.io/clouditor/api/auth"
-	"clouditor.io/clouditor/cli"
 	"clouditor.io/clouditor/persistence"
 	service_auth "clouditor.io/clouditor/service/auth"
 	"github.com/spf13/viper"
@@ -67,7 +66,7 @@ func TestMain(m *testing.M) {
 func TestSession(t *testing.T) {
 	var (
 		err     error
-		session *cli.Session
+		session *Session
 		dir     string
 	)
 	defer sock.Close()
@@ -79,7 +78,7 @@ func TestSession(t *testing.T) {
 
 	viper.Set("session-directory", dir)
 
-	session, err = cli.NewSession(fmt.Sprintf("localhost:%d", sock.Addr().(*net.TCPAddr).Port))
+	session, err = NewSession(fmt.Sprintf("localhost:%d", sock.Addr().(*net.TCPAddr).Port))
 	if err != nil {
 		t.Fatalf("Failed to dial bufnet: %v", err)
 	}
@@ -107,7 +106,7 @@ func TestSession(t *testing.T) {
 
 	assert.Nil(t, err)
 
-	session, err = cli.ContinueSession()
+	session, err = ContinueSession()
 	assert.Nil(t, err)
 	assert.NotNil(t, session)
 
@@ -176,7 +175,7 @@ func TestSession_HandleResponse(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			s := &cli.Session{
+			s := &Session{
 				URL:        tt.fields.URL,
 				Token:      tt.fields.Token,
 				Folder:     tt.fields.Folder,
@@ -189,6 +188,6 @@ func TestSession_HandleResponse(t *testing.T) {
 
 // Test will fail due to no user input
 func TestPromptForLogin(t *testing.T) {
-	_, err := cli.PromptForLogin()
+	_, err := PromptForLogin()
 	assert.NotNil(t, err)
 }
diff --git a/policies/policies_test.go b/policies/policies_test.go
index 5bd18906..b67a3f78 100644
--- a/policies/policies_test.go
+++ b/policies/policies_test.go
@@ -23,7 +23,7 @@
 //
 // This file is part of Clouditor Community Edition.
 
-package policies_test
+package policies
 
 import (
 	"os"
@@ -32,7 +32,6 @@ import (
 	"clouditor.io/clouditor/voc"
 
 	"clouditor.io/clouditor/api/evidence"
-	"clouditor.io/clouditor/policies"
 	"github.com/stretchr/testify/assert"
 )
 
@@ -254,7 +253,7 @@ func TestRunEvidence(t *testing.T) {
 		resource, err := voc.ToStruct(tt.fields.resource)
 		assert.Nil(t, err)
 		t.Run(tt.name, func(t *testing.T) {
-			results, err := policies.RunEvidence(&evidence.Evidence{
+			results, err := RunEvidence(&evidence.Evidence{
 				Id:       tt.fields.evidenceID,
 				Resource: resource,
 			})
diff --git a/service/discovery/k8s/compute_test.go b/service/discovery/k8s/compute_test.go
index b0ce0729..762aa490 100644
--- a/service/discovery/k8s/compute_test.go
+++ b/service/discovery/k8s/compute_test.go
@@ -23,13 +23,12 @@
 //
 // This file is part of Clouditor Community Edition.
 
-package k8s_test
+package k8s
 
 import (
 	"context"
 	"testing"
 
-	"clouditor.io/clouditor/service/discovery/k8s"
 	"clouditor.io/clouditor/voc"
 	"github.com/stretchr/testify/assert"
 	corev1 "k8s.io/api/core/v1"
@@ -46,7 +45,7 @@ func TestListPods(t *testing.T) {
 		t.Fatalf("error injecting pod add: %v", err)
 	}
 
-	d := k8s.NewKubernetesComputeDiscovery(client)
+	d := NewKubernetesComputeDiscovery(client)
 
 	list, err := d.List()
 
diff --git a/service/discovery/k8s/network_test.go b/service/discovery/k8s/network_test.go
index c117bb98..40dc0a77 100644
--- a/service/discovery/k8s/network_test.go
+++ b/service/discovery/k8s/network_test.go
@@ -23,13 +23,12 @@
 //
 // This file is part of Clouditor Community Edition.
 
-package k8s_test
+package k8s
 
 import (
 	"context"
 	"testing"
 
-	"clouditor.io/clouditor/service/discovery/k8s"
 	"clouditor.io/clouditor/voc"
 	"github.com/stretchr/testify/assert"
 	v1 "k8s.io/api/core/v1"
@@ -87,7 +86,7 @@ func TestListIngresses(t *testing.T) {
 		t.Fatalf("error injecting service add: %v", err)
 	}
 
-	d := k8s.NewKubernetesNetworkDiscovery(client)
+	d := NewKubernetesNetworkDiscovery(client)
 
 	list, err := d.List()
 
diff --git a/service/orchestrator/cloud_service_test.go b/service/orchestrator/cloud_service_test.go
index 42629cef..206ee29a 100644
--- a/service/orchestrator/cloud_service_test.go
+++ b/service/orchestrator/cloud_service_test.go
@@ -1,11 +1,10 @@
-package orchestrator_test
+package orchestrator
 
 import (
 	"context"
 	"testing"
 
 	"clouditor.io/clouditor/api/orchestrator"
-	service_orchestrator "clouditor.io/clouditor/service/orchestrator"
 	"github.com/stretchr/testify/assert"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
@@ -96,9 +95,9 @@ func TestGetCloudService(t *testing.T) {
 			"valid",
 			&orchestrator.GetCloudServiceRequest{ServiceId: defaultTarget.Id},
 			&orchestrator.CloudService{
-				Id:          service_orchestrator.DefaultTargetCloudServiceId,
-				Name:        service_orchestrator.DefaultTargetCloudServiceName,
-				Description: service_orchestrator.DefaultTargetCloudServiceDescription,
+				Id:          DefaultTargetCloudServiceId,
+				Name:        DefaultTargetCloudServiceName,
+				Description: DefaultTargetCloudServiceDescription,
 			},
 			nil,
 		},
diff --git a/service/orchestrator/orchestrator_test.go b/service/orchestrator/orchestrator_test.go
index a2f6074d..1f0aac04 100644
--- a/service/orchestrator/orchestrator_test.go
+++ b/service/orchestrator/orchestrator_test.go
@@ -23,7 +23,7 @@
 //
 // This file is part of Clouditor Community Edition.
 
-package orchestrator_test
+package orchestrator
 
 import (
 	"context"
@@ -34,7 +34,6 @@ import (
 	"io"
 	"io/fs"
 	"k8s.io/apimachinery/pkg/util/json"
-	"log"
 	"os"
 	"reflect"
 	"runtime"
@@ -45,11 +44,10 @@ import (
 	"clouditor.io/clouditor/persistence"
 
 	"clouditor.io/clouditor/api/orchestrator"
-	service_orchestrator "clouditor.io/clouditor/service/orchestrator"
 	"github.com/stretchr/testify/assert"
 )
 
-var service *service_orchestrator.Service
+var service *Service
 var defaultTarget *orchestrator.CloudService
 
 func TestMain(m *testing.M) {
@@ -63,7 +61,7 @@ func TestMain(m *testing.M) {
 		panic(err)
 	}
 
-	service = service_orchestrator.NewService()
+	service = NewService()
 	defaultTarget, err = service.CreateDefaultTargetCloudService()
 	if err != nil {
 		panic(err)
@@ -91,7 +89,7 @@ func TestAssessmentResultHook(t *testing.T) {
 		ready2 <- true
 	}
 
-	service := service_orchestrator.NewService()
+	service := NewService()
 	service.RegisterAssessmentResultHook(firstHookFunction)
 	service.RegisterAssessmentResultHook(secondHookFunction)
 
@@ -169,7 +167,7 @@ func TestAssessmentResultHook(t *testing.T) {
 			if !reflect.DeepEqual(gotResp, tt.wantResp) {
 				t.Errorf("StoreAssessmentResult() gotResp = %v, want %v", gotResp, tt.wantResp)
 			}
-			assert.NotEmpty(t, s.Results)
+			assert.NotEmpty(t, s.results)
 			assert.Equal(t, 2, hookCallCounter)
 		})
 	}
@@ -279,7 +277,7 @@ func TestStoreAssessmentResult(t *testing.T) {
 
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			s := service_orchestrator.NewService()
+			s := NewService()
 			gotResp, err := s.StoreAssessmentResult(tt.args.in0, tt.args.assessment)
 			if (err != nil) != tt.wantErr {
 				t.Errorf("StoreAssessmentResult() error = %v, wantErr %v", err, tt.wantErr)
@@ -290,9 +288,9 @@ func TestStoreAssessmentResult(t *testing.T) {
 			}
 
 			if err == nil {
-				assert.NotNil(t, s.Results["assessmentResultID"])
+				assert.NotNil(t, s.results["assessmentResultID"])
 			} else {
-				assert.Empty(t, s.Results)
+				assert.Empty(t, s.results)
 			}
 		})
 	}
@@ -317,21 +315,21 @@ func TestStoreAssessmentResults(t *testing.T) {
 
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			s := service_orchestrator.NewService()
+			s := NewService()
 			if err := s.StoreAssessmentResults(tt.args.stream); (err != nil) != tt.wantErr {
 				t.Errorf("StoreAssessmentResults() error = %v, wantErr %v", err, tt.wantErr)
-				assert.Equal(t, 2, len(s.Results))
+				assert.Equal(t, 2, len(s.results))
 			}
 		})
 	}
 }
 
 func TestLoad(t *testing.T) {
-	var err = service_orchestrator.LoadMetrics("notfound.json")
+	var err = LoadMetrics("notfound.json")
 
 	assert.ErrorIs(t, err, fs.ErrNotExist)
 
-	err = service_orchestrator.LoadMetrics("metrics.json")
+	err = LoadMetrics("metrics.json")
 
 	assert.Nil(t, err)
 }