package integration_test

import (
	"io/ioutil"
	"os"
	"testing"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	bmtestutils "github.com/cloudfoundry/bosh-micro-cli/testutils"
)

var testCpiFilePath string

func TestIntegration(t *testing.T) {
	RegisterFailHandler(Fail)
	BeforeSuite(func() {
		err := bmtestutils.BuildExecutable()
		Expect(err).NotTo(HaveOccurred())

		testCpiFilePath, err = bmtestutils.DownloadTestCpiRelease("")
		Expect(err).NotTo(HaveOccurred())
	})

	var (
		homePath string
		oldHome  string
	)
	BeforeEach(func() {
		oldHome = os.Getenv("HOME")

		var err error
		homePath, err = ioutil.TempDir("", "micro-bosh-cli-integration")
		Expect(err).NotTo(HaveOccurred())

		err = os.Setenv("HOME", homePath)
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		err := os.Setenv("HOME", oldHome)
		Expect(err).NotTo(HaveOccurred())

		err = os.RemoveAll(homePath)
		Expect(err).NotTo(HaveOccurred())
	})

	AfterSuite(func() {
		err := os.Remove(testCpiFilePath)
		Expect(err).NotTo(HaveOccurred())
	})

	RunSpecs(t, "bosh-micro-cli Integration Suite")
}

package integration_test

import (
	"io/ioutil"
	"os"
	"testing"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	bmtestutils "github.com/cloudfoundry/bosh-micro-cli/testutils"
)

var testCpiFilePath string

func TestIntegration(t *testing.T) {
	RegisterFailHandler(Fail)
	BeforeSuite(func() {
		err := bmtestutils.BuildExecutable()
		Expect(err).NotTo(HaveOccurred())

		testCpiFilePath, err = bmtestutils.DownloadTestCpiRelease("")
		Expect(err).NotTo(HaveOccurred())
	})

	var (
		homePath string
		oldHome  string
	)
	BeforeEach(func() {
		oldHome = os.Getenv("HOME")

		var err error
		homePath, err = ioutil.TempDir("", "micro-bosh-cli-integration")
		Expect(err).NotTo(HaveOccurred())
		os.Setenv("HOME", homePath)
	})

	AfterEach(func() {
		os.Setenv("HOME", oldHome)
		os.RemoveAll(homePath)
	})

	AfterSuite(func() {
		os.Remove(testCpiFilePath)
	})

	RunSpecs(t, "bosh-micro-cli Integration Suite")
}

--- 
+++ 
@@ -33,16 +33,22 @@
 		var err error
 		homePath, err = ioutil.TempDir("", "micro-bosh-cli-integration")
 		Expect(err).NotTo(HaveOccurred())
-		os.Setenv("HOME", homePath)
+
+		err = os.Setenv("HOME", homePath)
+		Expect(err).NotTo(HaveOccurred())
 	})
 
 	AfterEach(func() {
-		os.Setenv("HOME", oldHome)
-		os.RemoveAll(homePath)
+		err := os.Setenv("HOME", oldHome)
+		Expect(err).NotTo(HaveOccurred())
+
+		err = os.RemoveAll(homePath)
+		Expect(err).NotTo(HaveOccurred())
 	})
 
 	AfterSuite(func() {
-		os.Remove(testCpiFilePath)
+		err := os.Remove(testCpiFilePath)
+		Expect(err).NotTo(HaveOccurred())
 	})
 
 	RunSpecs(t, "bosh-micro-cli Integration Suite")
Check for errors for operations in BeforeEach and AfterEach/Suite.

Signed-off-by: Phan Le <f2c5995718b197bbd6f63c99e8aab6ee2af1c495@pivotallabs.com>
