Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Commit

Permalink
Rearrange test cases and util files (Issue #472) (#1243)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuklanirdesh82 committed May 12, 2017
1 parent 25e1a4e commit 8c44615
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
// TODO: as of now we are running the test against photon vm it should be run
// against various/applicable linux distros.

package e2e_test
package e2e

import (
volumeNameUtil "github.com/vmware/docker-volume-vsphere/vmdk_plugin/utils"
TestUtil "github.com/vmware/docker-volume-vsphere/vmdk_plugin/utils/test_util"
testparams "github.com/vmware/docker-volume-vsphere/tests/utils/inputparams"
dockercli "github.com/vmware/docker-volume-vsphere/tests/utils/dockercli"
"os"
"testing"
)
Expand Down Expand Up @@ -52,17 +52,17 @@ func TestVolumeCreationFirstTime(t *testing.T) {
var err error
var out []byte
for _, host := range dockerHosts {
volumeName := volumeNameUtil.GetVolumeNameWithTimeStamp("abc")
volumeName := testparams.GetVolumeNameWithTimeStamp("abc")

// create volume
out, err = TestUtil.CreateDefaultVolume(host, volumeName)
out, err = dockercli.CreateDefaultVolume(host, volumeName)

if err != nil {
t.Errorf("\nError has occurred [%s] \n\twhile creating volume [%s] very first time: err -> %v", out, volumeName, err)
} else {
t.Logf("\nTestcase passed: successfully able to create volume [%s]\n", out)
// delete volume
TestUtil.DeleteVolume(volumeName, host)
dockercli.DeleteVolume(volumeName, host)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

// Test assumes that SSH cert has been setup to enable password-less login to VM and ESX.

package e2e_test
package e2e

import (
"github.com/vmware/docker-volume-vsphere/vmdk_plugin/utils"
TestUtil "github.com/vmware/docker-volume-vsphere/vmdk_plugin/utils/test_util"
dkrcli "github.com/vmware/docker-volume-vsphere/tests/utils/dockercli"
testparams "github.com/vmware/docker-volume-vsphere/tests/utils/inputparams"
verifier "github.com/vmware/docker-volume-vsphere/tests/utils/verification"
"log"
"os"
"strconv"
Expand Down Expand Up @@ -50,7 +51,7 @@ func TestMain(m *testing.M) {

// clean-up function
func teardownFunction() {
TestUtil.ExecCmd(vmIp, dockerVolmRmvCmd)
verifier.ExecCmd(vmIp, dockerVolmRmvCmd)
log.Println("-----Clean-up finished - current time: ", time.Now())
}

Expand All @@ -70,13 +71,13 @@ func TestVolumeProperties(t *testing.T) {
log.Println("running end_to_end tests - current time: ", time.Now())
vmIp = vms[vmIndx]
log.Println("Running test on VM - ", vmIp)
dockerCliCheck = TestUtil.IsDockerCliCheckNeeded(vms[vmIndx])
dockerCliCheck = verifier.IsDockerCliCheckNeeded(vms[vmIndx])
for i := 0; i < len(volSizes); i++ {
for k := 0; k < len(formatTypes); k++ {
containerName = "busybox_" + strconv.FormatInt(time.Now().Unix(), 20)
log.Println("Creating a volume of Format Type - ", formatTypes[k])
volName := TestInputParamsUtil.GetVolumeNameWithTimeStamp("dockerVol")
_, err := TestUtil.InvokeCommand(vms[vmIndx], "docker volume create --driver=vsphere --name="+
volName := testparams.GetVolumeNameWithTimeStamp("dockerVol")
_, err := dkrcli.InvokeCommand(vms[vmIndx], "docker volume create --driver=vsphere --name="+
volName+" -o size="+volSizes[i]+" -o diskformat="+formatTypes[k])
if err != nil {
log.Fatalf("Failed to create a volume named: %s. Error - %v ", volName, err)
Expand All @@ -86,43 +87,43 @@ func TestVolumeProperties(t *testing.T) {
}
log.Println("Verifying volume properties like size, disk-format and attached-to-vm fields "+
"at vm and esx for volume - ", volName)
volmPropertiesAdminCli := TestUtil.GetVolumePropertiesAdminCli(volName, esx)
volmPropertiesAdminCli := verifier.GetVolumePropertiesAdminCli(volName, esx)
expctdPropsAdmin := []string{"100MB", formatTypes[k], "detached"}
if !hasElement(expctdPropsAdmin, volmPropertiesAdminCli) {
log.Fatal("Volume properties on ESX fetched using admin cli does not matches with the expected values")
}

if dockerCliCheck {
volmPropertiesDkrCli := TestUtil.GetVolumePropertiesDockerCli(volName, vms[vmIndx])
volmPropertiesDkrCli := verifier.GetVolumePropertiesDockerCli(volName, vms[vmIndx])
expctdPropsDkr := []string{"100MB", formatTypes[k], "<no value>"}
if !hasElement(expctdPropsDkr, volmPropertiesDkrCli) {
log.Fatal("Volume properties fetched using docker cli do not matches with the expected values")
}
}
TestUtil.InvokeCommand(vms[vmIndx], "docker run -d -v "+volName+":/vol --name "+containerName+" busybox tail -f /dev/null")
dkrcli.InvokeCommand(vms[vmIndx], "docker run -d -v "+volName+":/vol --name "+containerName+" busybox tail -f /dev/null")
// Verifying attached to the vm field for volume
vmNameFrmAdminCli := TestUtil.GetVmAttachedToVolUsingAdminCli(volName, esx)
vmNameFrmAdminCli := verifier.GetVmAttachedToVolUsingAdminCli(volName, esx)
if dockerCliCheck {
vmNameFrmDockerCli := TestUtil.GetVmAttachedToVolUsingDockerCli(volName, vms[vmIndx])
vmNameFrmDockerCli := verifier.GetVmAttachedToVolUsingDockerCli(volName, vms[vmIndx])
// TODO: get vm name based on ip and compare ith with the docker cli and admin cli
if vmNameFrmDockerCli != vmNameFrmAdminCli {
log.Fatalf("Information mis-match - Attached-to-VM field for volume from docker cli is [%s]"+
"and attched-to-vm field from admin cli is [%s]", vmNameFrmDockerCli, vmNameFrmAdminCli)
}
volmPropertiesDkrCli := TestUtil.GetVolumePropertiesDockerCli(volName, vms[vmIndx])
volmPropertiesDkrCli := verifier.GetVolumePropertiesDockerCli(volName, vms[vmIndx])
expctdPropsDkr := []string{"100MB", formatTypes[k]}
if !hasElement(expctdPropsDkr, volmPropertiesDkrCli) {
log.Fatal("Volume properties on ESX fetched using docker cli do not matches with the expected values")
}
}
volmPropertiesAdminCli = TestUtil.GetVolumePropertiesAdminCli(volName, esx)
volmPropertiesAdminCli = verifier.GetVolumePropertiesAdminCli(volName, esx)
expctdPropsAdmin = []string{"100MB", formatTypes[k]}
if !hasElement(expctdPropsAdmin, volmPropertiesAdminCli) {
log.Fatal("Volume properties on admin cli do not matches with the expected values")
}
log.Println("Finished verifying volume properties like size, disk-format and attached-to-vm fields"+
" at vm and esx for volume - ", volName)
TestUtil.ExecCmd(vms[vmIndx], "docker stop "+containerName+" ; docker rm "+containerName)
verifier.ExecCmd(vms[vmIndx], "docker stop "+containerName+" ; docker rm "+containerName)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// This util is going to hold various helper methods to be consumed by testcase.
// Volume creation, deletion is supported as of now.

package e2e
package utils

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package TestInputParamsUtil
package utils

// This file holds basic utility/helper methods for object creation used
// at test methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
// fetch information like capacity, disk-format and attched-to-vm fields
// for volume using docker cli or admin cli.

package e2e
package utils

import (
"log"
"strings"
sshutil "github.com/vmware/docker-volume-vsphere/tests/utils/dockercli"
)

var ADMIN_CLI_LS = "/usr/lib/vmware/vmdkops/bin/vmdkops_admin.py volume ls "
Expand Down Expand Up @@ -99,7 +100,7 @@ func GetDockerVersion(hostname string) string {
//method takes command and host and calls InvokeCommand
//and then returns the output after converting to string
func ExecCmd(hostname string, cmd string) string {
out, err := InvokeCommand(hostname, cmd)
out, err := sshutil.InvokeCommand(hostname, cmd)
if err != nil {
log.Fatal(err)
}
Expand Down
15 changes: 11 additions & 4 deletions vmdk_plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ VIB_BIN := $(BIN)/$(VIBFILE)
# plugin name, for go build
PLUGIN := github.com/$(GOPATH_ORG)/$(GOPATH_PLUGNAME)

# test location, picking up E2E tests
E2E_Tests := github.com/$(GOPATH_ORG)/$(PLUGNAME)/tests/e2e

GO := GO15VENDOREXPERIMENT=1 go
FPM := fpm

Expand All @@ -93,9 +96,13 @@ VMDKOPS_MODULE_SRC = $(VMDKOPS_MODULE)/*.go $(VMCI_SRC)

# All sources. We rebuild if anything changes here
SRC = main.go log_formatter.go utils/refcount/refcnt.go \
utils/fs/fs.go utils/config/config.go utils/TestInputParamsUtil.go utils/plugin_utils/plugin_utils.go\
utils/fs/fs.go utils/config/config.go utils/plugin_utils/plugin_utils.go\
drivers/photon/photon_driver.go drivers/vmdk/vmdk_driver.go

TEST_SRC = ../tests/utils/inputparams/TestInputParamsUtil.go \
../tests/utils/dockercli/VolumeCreationTestUtil.go \
../tests/utils/verification/VolumePropertiesVerificationUtil.go

# Canned recipe
define log_target
@echo
Expand Down Expand Up @@ -136,10 +143,10 @@ $(PLUGIN_BIN): $(SRC) $(VMDKOPS_MODULE_SRC)
@-mkdir -p $(BIN) && chmod a+w $(BIN)
$(GO) build --ldflags '-extldflags "-static"' -o $(PLUGIN_BIN) $(PLUGIN)

$(BIN)/$(VMDKOPS_TEST_MODULE).test: $(VMDKOPS_MODULE_SRC) $(VMDKOPS_MODULE)/*_test.go
$(BIN)/$(VMDKOPS_TEST_MODULE).test: $(VMDKOPS_MODULE_SRC) $(TEST_SRC) $(VMDKOPS_MODULE)/*_test.go
$(GO) test -c -o $@ $(PLUGIN)/$(VMDKOPS_MODULE) -cover

$(BIN)/$(PLUGNAME).test: $(SRC) *_test.go
$(BIN)/$(PLUGNAME).test: $(SRC) $(TEST_SRC) *_test.go
$(GO) test -c -o $@ $(PLUGIN) -cover

.PHONY: clean
Expand Down Expand Up @@ -347,7 +354,7 @@ e2e-test:
.PHONY: e2e-dkrVolDriver-test
e2e-dkrVolDriver-test:
$(log_target)
$(GO) test $(PLUGIN)/E2E_Tests -cover -v
$(GO) test $(E2E_Tests) -v

MANAGED_PLUGIN_NAME="vsphere:latest"

Expand Down
4 changes: 2 additions & 2 deletions vmdk_plugin/drivers/vmdk/vmdkops/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package vmdkops_test

import (
"github.com/stretchr/testify/assert"
testparams "github.com/vmware/docker-volume-vsphere/tests/utils/inputparams"
"github.com/vmware/docker-volume-vsphere/vmdk_plugin/drivers/vmdk/vmdkops"
"github.com/vmware/docker-volume-vsphere/vmdk_plugin/utils"
"testing"
)

func TestCommands(t *testing.T) {
ops := vmdkops.VmdkOps{Cmd: vmdkops.MockVmdkCmd{}}
name := TestInputParamsUtil.GetVolumeName()
name := testparams.GetVolumeName()
t.Logf("\nCreating Test Volume with name = [%s]...\n", name)
opts := map[string]string{"size": "2gb"}
if assert.Nil(t, ops.Create(name, opts)) {
Expand Down
12 changes: 6 additions & 6 deletions vmdk_plugin/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/docker/engine-api/types/container"
"github.com/docker/engine-api/types/filters"
"github.com/docker/engine-api/types/strslice"
"github.com/vmware/docker-volume-vsphere/vmdk_plugin/utils"
testutil "github.com/vmware/docker-volume-vsphere/tests/utils/inputparams"
"github.com/vmware/docker-volume-vsphere/vmdk_plugin/utils/config"
"github.com/vmware/docker-volume-vsphere/vmdk_plugin/utils/refcount"
"golang.org/x/net/context"
Expand Down Expand Up @@ -189,8 +189,8 @@ func volumeVmdkExists(t *testing.T, c *client.Client, vol string) *types.Volume
func getClients(t *testing.T) []testClient {

clients := []testClient{
{TestInputParamsUtil.GetEndPoint1(), new(client.Client)},
{TestInputParamsUtil.GetEndPoint2(), new(client.Client)},
{testutil.GetEndPoint1(), new(client.Client)},
{testutil.GetEndPoint2(), new(client.Client)},
}

for idx, elem := range clients {
Expand All @@ -211,11 +211,11 @@ func getClients(t *testing.T) []testClient {
func TestSanity(t *testing.T) {

fmt.Printf("%s START: Running TestSanity on %s (may take a while)...\n",
time.Now().Format(time.RFC3339), TestInputParamsUtil.GetEndPoint1())
time.Now().Format(time.RFC3339), testutil.GetEndPoint1())

clients := getClients(t)
c := clients[0].client // this is the endpoint we use as master
volumeName := TestInputParamsUtil.GetVolumeName()
volumeName := testutil.GetVolumeName()
t.Logf("Creating vol=%s on client %s.", volumeName, clients[0].endPoint)
_, err := c.VolumeCreate(context.Background(),
types.VolumeCreateRequest{
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestSanity(t *testing.T) {
}
}
fmt.Printf("%s END: Running TestSanity on %s (may take a while)...\n",
time.Now().Format(time.RFC3339), TestInputParamsUtil.GetEndPoint1())
time.Now().Format(time.RFC3339), testutil.GetEndPoint1())

}

Expand Down

0 comments on commit 8c44615

Please sign in to comment.