Skip to content

Commit

Permalink
chore(cleanup): testutils/mock_context.go (#1436)
Browse files Browse the repository at this point in the history
Co-authored-by: Ian Eyberg <[email protected]>
  • Loading branch information
rinor and eyberg authored Feb 22, 2023
1 parent e773e56 commit c5e21c5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 36 deletions.
8 changes: 4 additions & 4 deletions provider/oci/oci_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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("")}).
Expand Down Expand Up @@ -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("")}).
Expand Down
15 changes: 7 additions & 8 deletions provider/oci/oci_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down Expand Up @@ -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("")}).
Expand All @@ -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("")}).
Expand All @@ -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("")}).
Expand All @@ -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("")}).
Expand All @@ -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("")}).
Expand Down Expand Up @@ -275,7 +274,7 @@ func TestAddInstancesNetworkDetails(t *testing.T) {
},
}, nil)

ctx := testutils.NewMockContext()
ctx := lepton.NewContext(lepton.NewConfig())

err := p.AddInstancesNetworkDetails(ctx, instances)

Expand Down
13 changes: 8 additions & 5 deletions provider/upcloud/upcloud_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)

Expand All @@ -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)
}
12 changes: 7 additions & 5 deletions provider/upcloud/upcloud_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)

Expand Down Expand Up @@ -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)
}
10 changes: 6 additions & 4 deletions provider/upcloud/upcloud_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
10 changes: 0 additions & 10 deletions testutils/mock_context.go

This file was deleted.

0 comments on commit c5e21c5

Please sign in to comment.