Browse Source

convert to gocheck.

Signed-off-by: Erik Hollensbe <github@hollensbe.org>
master
Erik Hollensbe 6 years ago
parent
commit
79ec21aa36
  1. 2
      Makefile
  2. 23
      providers/vmware/disk_test.go
  3. 15
      providers/vmware/init_test.go
  4. 15
      providers/vmware/provider_test.go
  5. 42
      providers/vmware/vmx_parser_test.go
  6. 25
      vcontrol_test.go

2
Makefile

@ -5,7 +5,7 @@ test: golint
dir="$$(echo $${GOPATH} | awk -F: '{ print $$1 }')/src/$${pkg}"; \
out="$$dir/cover.out"; \
echo "$$out"; \
go test -v "$$pkg" -coverprofile="$$out"; \
go test -v "$$pkg" -coverprofile="$$out" -check.v; \
go tool cover -html="$$out" -o "$$dir/coverage.html" 2>/dev/null || :; \
done

23
providers/vmware/disk_test.go

@ -2,23 +2,17 @@ package vmware
import (
"fmt"
"testing"
. "gopkg.in/check.v1"
)
func TestDiskControllerParams(t *testing.T) {
func (vs *vmwareSuite) TestDiskControllerParams(c *C) {
vp := centosDiskControllers[0].(*DiskController).toParams(0)
if vp == nil {
t.Fatal("disk controller params were nil")
}
if vp["floppy0.present"] != fmt.Sprintf("%v", false) {
t.Fatalf("invalid present value for first controller: %v", vp)
}
c.Assert(vp, NotNil)
c.Assert(vp["floppy0.present"], Equals, fmt.Sprintf("%v", false))
vp = centosDiskControllers[1].(*DiskController).toParams(0)
if vp == nil {
t.Fatal("disk controller #2 params were nil")
}
c.Assert(vp, NotNil)
typeMap := map[string]interface{}{
"scsi0.present": true,
@ -27,9 +21,6 @@ func TestDiskControllerParams(t *testing.T) {
}
for key, val := range typeMap {
if vp[key] != fmt.Sprintf("%v", val) {
t.Log(vp)
t.Fatalf("Key %q (%v) does not match expected value %v", key, val, typeMap[key])
}
c.Assert(vp[key], Equals, fmt.Sprintf("%v", val))
}
}

15
providers/vmware/init_test.go

@ -0,0 +1,15 @@
package vmware
import (
. "testing"
. "gopkg.in/check.v1"
)
type vmwareSuite struct{}
var _ = Suite(&vmwareSuite{})
func TestVMWare(t *T) {
TestingT(t)
}

15
providers/vmware/provider_test.go

@ -2,21 +2,18 @@ package vmware
import (
"os"
"testing"
. "gopkg.in/check.v1"
"github.com/erikh/vcontrol/context"
)
func TestAvailable(t *testing.T) {
func (vs *vmwareSuite) TestAvailable(c *C) {
vmw := &Provider{}
if err := vmw.Available(&context.Context{Environment: os.Environ()}); err != nil {
t.Fatalf("Could not find 'vmrun' in path: %v", err)
}
c.Assert(vmw.Available(&context.Context{Environment: os.Environ()}), IsNil)
}
func TestInit(t *testing.T) {
func (vs *vmwareSuite) TestInit(c *C) {
vmw := &Provider{}
if err := vmw.Init(&context.Context{Environment: os.Environ()}); err != nil {
t.Fatal(err)
}
c.Assert(vmw.Init(&context.Context{Environment: os.Environ()}), IsNil)
}

42
providers/vmware/vmx_parser_test.go

@ -1,40 +1,18 @@
package vmware
import (
"reflect"
"testing"
)
import . "gopkg.in/check.v1"
func TestVMXParamsRead(t *testing.T) {
func (vs *vmwareSuite) TestVMXParamsRead(c *C) {
vp := VMXParams{}
if err := vp.read("vmx_parser_testdata/example.vmx"); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(vp, exampleParams) {
t.Fatal("read parameters do not match fixture")
}
c.Assert(vp.read("vmx_parser_testdata/example.vmx"), IsNil)
c.Assert(vp, DeepEquals, exampleParams)
}
func TestVMXFromFile(t *testing.T) {
func (vs *vmwareSuite) TestVMXFromFile(c *C) {
vmx, err := NewVMXFromFile("vmx_parser_testdata/centos72.vmx")
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(vmx.Disks(), centosDisks) {
t.Fatal("Disks did not match")
}
if !reflect.DeepEqual(vmx.Ethernets(), centosEthernets) {
t.Fatal("Ethernets did not match")
}
if !reflect.DeepEqual(vmx.DiskControllers(), centosDiskControllers) {
t.Fatal("DiskControllers did not match")
}
if !reflect.DeepEqual(vmx.SharedFolders(), centosSharedFolders) {
t.Fatal("Shared folders did not match")
}
c.Assert(err, IsNil)
c.Assert(vmx.Disks(), DeepEquals, centosDisks)
c.Assert(vmx.Ethernets(), DeepEquals, centosEthernets)
c.Assert(vmx.DiskControllers(), DeepEquals, centosDiskControllers)
c.Assert(vmx.SharedFolders(), DeepEquals, centosSharedFolders)
}

25
vcontrol_test.go

@ -2,20 +2,27 @@ package vcontrol
import (
"os"
"testing"
. "testing"
. "gopkg.in/check.v1"
"github.com/erikh/vcontrol/context"
"github.com/erikh/vcontrol/providers/vmware"
)
func TestInitWithProviders(t *testing.T) {
type vcontrolSuite struct{}
var _ = Suite(&vcontrolSuite{})
func TestVControl(t *T) {
TestingT(t)
}
func (vc *vcontrolSuite) TestInitWithProviders(c *C) {
vmw := &vmware.Provider{}
ctx, err := InitWithProviders([]context.Provider{vmw}, os.Environ())
if err != nil {
t.Fatal(err)
}
if !(len(ctx.Providers) == 1 && ctx.Providers[0].Name() == "vmware") {
t.Fatal("Could not find provider in supplied list")
}
c.Assert(ctx, NotNil)
c.Assert(err, IsNil)
c.Assert(len(ctx.Providers), Equals, 1)
c.Assert(ctx.Providers[0].Name(), Equals, "vmware")
}

Loading…
Cancel
Save