From c5e21c58eb7ed24597548853b9315284275a39c9 Mon Sep 17 00:00:00 2001 From: Rinor Hoxha Date: Wed, 22 Feb 2023 02:26:34 +0100 Subject: [PATCH] chore(cleanup): testutils/mock_context.go (#1436) Co-authored-by: Ian Eyberg --- provider/oci/oci_image_test.go | 8 ++++---- provider/oci/oci_instance_test.go | 15 +++++++-------- provider/upcloud/upcloud_image_test.go | 13 ++++++++----- provider/upcloud/upcloud_instance_test.go | 12 +++++++----- provider/upcloud/upcloud_volume_test.go | 10 ++++++---- testutils/mock_context.go | 10 ---------- 6 files changed, 32 insertions(+), 36 deletions(-) delete mode 100644 testutils/mock_context.go diff --git a/provider/oci/oci_image_test.go b/provider/oci/oci_image_test.go index 380e7747..af137a20 100644 --- a/provider/oci/oci_image_test.go +++ b/provider/oci/oci_image_test.go @@ -78,7 +78,7 @@ func PutObjectMatcher(x objectstorage.PutObjectRequest) gomock.Matcher { func TestBuildImage(t *testing.T) { p, _, _, _, _, _, _ := NewProvider(t) - ctx := testutils.NewMockContext() + ctx := lepton.NewContext(lepton.NewConfig()) imageName := "oci-build-image-test" @@ -103,7 +103,7 @@ func TestCreateImage(t *testing.T) { cloudImageName := "main" bucketName := "test-bucket" bucketNamespace := "test-namespace" - ctx := testutils.NewMockContext() + ctx := lepton.NewContext(lepton.NewConfig()) ctx.Config().CloudConfig.ImageName = cloudImageName ctx.Config().CloudConfig.BucketName = bucketName @@ -141,7 +141,7 @@ func TestCreateImage(t *testing.T) { func TestListImages(t *testing.T) { p, computeService, _, _, _, _, _ := NewProvider(t) - ctx := testutils.NewMockContext() + ctx := lepton.NewContext(lepton.NewConfig()) computeService.EXPECT(). ListImages(context.TODO(), core.ListImagesRequest{CompartmentId: types.StringPtr("")}). @@ -186,7 +186,7 @@ func TestListImages(t *testing.T) { func TestDeleteImage(t *testing.T) { p, computeService, _, _, _, _, _ := NewProvider(t) - ctx := testutils.NewMockContext() + ctx := lepton.NewContext(lepton.NewConfig()) computeService.EXPECT(). ListImages(context.TODO(), core.ListImagesRequest{CompartmentId: types.StringPtr("")}). diff --git a/provider/oci/oci_instance_test.go b/provider/oci/oci_instance_test.go index 8e6c8926..e185982d 100644 --- a/provider/oci/oci_instance_test.go +++ b/provider/oci/oci_instance_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/nanovms/ops/lepton" - "github.com/nanovms/ops/testutils" "github.com/nanovms/ops/types" "github.com/oracle/oci-go-sdk/common" "github.com/oracle/oci-go-sdk/core" @@ -15,7 +14,7 @@ import ( func TestCreateInstance(t *testing.T) { p, c, _, _, n, _, _ := NewProvider(t) - ctx := testutils.NewMockContext() + ctx := lepton.NewContext(lepton.NewConfig()) instanceName := "instance-test" imageName := "image-test" @@ -148,7 +147,7 @@ func TestCreateInstance(t *testing.T) { func TestGetInstances(t *testing.T) { p, c, _, _, _, _, _ := NewProvider(t) - ctx := testutils.NewMockContext() + ctx := lepton.NewContext(lepton.NewConfig()) c.EXPECT(). ListInstances(context.TODO(), core.ListInstancesRequest{CompartmentId: types.StringPtr("")}). @@ -168,7 +167,7 @@ func TestGetInstances(t *testing.T) { func TestGetInstanceByID(t *testing.T) { p, c, _, _, _, _, _ := NewProvider(t) - ctx := testutils.NewMockContext() + ctx := lepton.NewContext(lepton.NewConfig()) c.EXPECT(). ListInstances(context.TODO(), core.ListInstancesRequest{CompartmentId: types.StringPtr("")}). @@ -185,7 +184,7 @@ func TestGetInstanceByID(t *testing.T) { func TestDeleteInstance(t *testing.T) { p, c, _, _, _, _, _ := NewProvider(t) - ctx := testutils.NewMockContext() + ctx := lepton.NewContext(lepton.NewConfig()) c.EXPECT(). ListInstances(context.TODO(), core.ListInstancesRequest{CompartmentId: types.StringPtr("")}). @@ -202,7 +201,7 @@ func TestDeleteInstance(t *testing.T) { func TestStartInstance(t *testing.T) { p, c, _, _, _, _, _ := NewProvider(t) - ctx := testutils.NewMockContext() + ctx := lepton.NewContext(lepton.NewConfig()) c.EXPECT(). ListInstances(context.TODO(), core.ListInstancesRequest{CompartmentId: types.StringPtr("")}). @@ -219,7 +218,7 @@ func TestStartInstance(t *testing.T) { func TestStopInstance(t *testing.T) { p, c, _, _, _, _, _ := NewProvider(t) - ctx := testutils.NewMockContext() + ctx := lepton.NewContext(lepton.NewConfig()) c.EXPECT(). ListInstances(context.TODO(), core.ListInstancesRequest{CompartmentId: types.StringPtr("")}). @@ -275,7 +274,7 @@ func TestAddInstancesNetworkDetails(t *testing.T) { }, }, nil) - ctx := testutils.NewMockContext() + ctx := lepton.NewContext(lepton.NewConfig()) err := p.AddInstancesNetworkDetails(ctx, instances) diff --git a/provider/upcloud/upcloud_image_test.go b/provider/upcloud/upcloud_image_test.go index 5ea4dc6b..b39b3735 100644 --- a/provider/upcloud/upcloud_image_test.go +++ b/provider/upcloud/upcloud_image_test.go @@ -8,7 +8,6 @@ import ( "github.com/UpCloudLtd/upcloud-go-api/upcloud" "github.com/UpCloudLtd/upcloud-go-api/upcloud/request" "github.com/nanovms/ops/lepton" - "github.com/nanovms/ops/testutils" "github.com/stretchr/testify/assert" ) @@ -41,7 +40,8 @@ func TestCreateImage(t *testing.T) { DeleteStorage(&request.DeleteStorageRequest{UUID: storageUUID}). Return(nil) - err := p.CreateImage(testutils.NewMockContext(), file.Name()) + ctx := lepton.NewContext(lepton.NewConfig()) + err := p.CreateImage(ctx, file.Name()) assert.Nil(t, err) } @@ -53,7 +53,8 @@ func TestListImages(t *testing.T) { GetStorages(&request.GetStoragesRequest{Access: "private", Type: "template"}). Return(&upcloud.Storages{}, nil) - err := p.ListImages(testutils.NewMockContext()) + ctx := lepton.NewContext(lepton.NewConfig()) + err := p.ListImages(ctx) assert.Nil(t, err) } @@ -65,7 +66,8 @@ func TestGetImages(t *testing.T) { GetStorages(&request.GetStoragesRequest{Access: "private", Type: "template"}). Return(&upcloud.Storages{}, nil) - images, err := p.GetImages(testutils.NewMockContext()) + ctx := lepton.NewContext(lepton.NewConfig()) + images, err := p.GetImages(ctx) assert.Nil(t, err) @@ -90,7 +92,8 @@ func TestDeleteImage(t *testing.T) { DeleteStorage(&request.DeleteStorageRequest{UUID: storageUUID}). Return(nil) - err := p.DeleteImage(testutils.NewMockContext(), storageTitle) + ctx := lepton.NewContext(lepton.NewConfig()) + err := p.DeleteImage(ctx, storageTitle) assert.Nil(t, err) } diff --git a/provider/upcloud/upcloud_instance_test.go b/provider/upcloud/upcloud_instance_test.go index dc6b9fe9..e8d5d92a 100644 --- a/provider/upcloud/upcloud_instance_test.go +++ b/provider/upcloud/upcloud_instance_test.go @@ -7,7 +7,6 @@ import ( "github.com/UpCloudLtd/upcloud-go-api/upcloud" "github.com/UpCloudLtd/upcloud-go-api/upcloud/request" "github.com/nanovms/ops/lepton" - "github.com/nanovms/ops/testutils" "github.com/stretchr/testify/assert" ) @@ -69,7 +68,7 @@ func TestCreateInstance(t *testing.T) { TagServer(&request.TagServerRequest{UUID: serverID, Tags: []string{"OPS", "image-test"}}). Return(&upcloud.ServerDetails{}, nil) - ctx := testutils.NewMockContext() + ctx := lepton.NewContext(lepton.NewConfig()) ctx.Config().CloudConfig.ImageName = imageName ctx.Config().RunConfig.InstanceName = instanceName err := p.CreateInstance(ctx) @@ -92,7 +91,8 @@ func TestListInstances(t *testing.T) { GetServers(). Return(&upcloud.Servers{}, nil) - err := p.ListInstances(testutils.NewMockContext()) + ctx := lepton.NewContext(lepton.NewConfig()) + err := p.ListInstances(ctx) assert.Nil(t, err) } @@ -112,7 +112,8 @@ func TestGetInstances(t *testing.T) { GetServers(). Return(&upcloud.Servers{}, nil) - instances, err := p.GetInstances(testutils.NewMockContext()) + ctx := lepton.NewContext(lepton.NewConfig()) + instances, err := p.GetInstances(ctx) assert.Nil(t, err) @@ -145,7 +146,8 @@ func TestDeleteInstance(t *testing.T) { DeleteServer(&request.DeleteServerRequest{UUID: serverID}). Return(nil) - err := p.DeleteInstance(testutils.NewMockContext(), serverName) + ctx := lepton.NewContext(lepton.NewConfig()) + err := p.DeleteInstance(ctx, serverName) assert.Nil(t, err) } diff --git a/provider/upcloud/upcloud_volume_test.go b/provider/upcloud/upcloud_volume_test.go index 2e68ab50..b95febe2 100644 --- a/provider/upcloud/upcloud_volume_test.go +++ b/provider/upcloud/upcloud_volume_test.go @@ -7,7 +7,6 @@ import ( "github.com/UpCloudLtd/upcloud-go-api/upcloud" "github.com/UpCloudLtd/upcloud-go-api/upcloud/request" "github.com/nanovms/ops/lepton" - "github.com/nanovms/ops/testutils" "github.com/stretchr/testify/assert" ) @@ -18,7 +17,8 @@ func TestGetAllVolumes(t *testing.T) { GetStorages(&request.GetStoragesRequest{Type: "disk", Access: "private"}). Return(&upcloud.Storages{}, nil) - volumes, err := p.GetAllVolumes(testutils.NewMockContext()) + ctx := lepton.NewContext(lepton.NewConfig()) + volumes, err := p.GetAllVolumes(ctx) assert.Nil(t, err) @@ -65,7 +65,8 @@ func TestAttachVolume(t *testing.T) { StartServer(&request.StartServerRequest{UUID: serverID}). Return(&upcloud.ServerDetails{Server: upcloud.Server{UUID: serverID, Title: serverName}}, nil) - err := p.AttachVolume(testutils.NewMockContext(), serverName, volumeName, 1) + ctx := lepton.NewContext(lepton.NewConfig()) + err := p.AttachVolume(ctx, serverName, volumeName, 1) assert.Nil(t, err) } @@ -110,7 +111,8 @@ func TestDetachVolume(t *testing.T) { StartServer(&request.StartServerRequest{UUID: serverID}). Return(&upcloud.ServerDetails{Server: upcloud.Server{UUID: serverID, Title: serverName}}, nil) - err := p.DetachVolume(testutils.NewMockContext(), serverName, volumeName) + ctx := lepton.NewContext(lepton.NewConfig()) + err := p.DetachVolume(ctx, serverName, volumeName) assert.Nil(t, err) } diff --git a/testutils/mock_context.go b/testutils/mock_context.go deleted file mode 100644 index 5d3fa252..00000000 --- a/testutils/mock_context.go +++ /dev/null @@ -1,10 +0,0 @@ -package testutils - -import ( - "github.com/nanovms/ops/lepton" -) - -// NewMockContext returns a context mock -func NewMockContext() *lepton.Context { - return lepton.NewContext(lepton.NewConfig()) -}