github.com/cloudfoundry-attic/garden-linux@v0.333.2-candidate/integration/networking/networking_suite_test.go (about)

     1  package networking_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"net"
     6  	"os"
     7  
     8  	"github.com/cloudfoundry-incubator/garden-linux/integration/runner"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  
    12  	"testing"
    13  	"time"
    14  )
    15  
    16  var externalIP net.IP
    17  var client *runner.RunningGarden
    18  
    19  func startGarden(argv ...string) *runner.RunningGarden {
    20  	return runner.Start(argv...)
    21  }
    22  
    23  func stopGarden() {
    24  	Expect(client.Stop()).To(Succeed())
    25  }
    26  
    27  func killGarden() {
    28  	client.Kill()
    29  }
    30  
    31  func TestNetworking(t *testing.T) {
    32  	var beforeSuite struct {
    33  		ExampleDotCom net.IP
    34  	}
    35  
    36  	SynchronizedBeforeSuite(func() []byte {
    37  		var err error
    38  
    39  		ips, err := net.LookupIP("www.example.com")
    40  		Expect(err).ToNot(HaveOccurred())
    41  		Expect(ips).ToNot(BeEmpty())
    42  		beforeSuite.ExampleDotCom = ips[0]
    43  
    44  		b, err := json.Marshal(beforeSuite)
    45  		Expect(err).ToNot(HaveOccurred())
    46  
    47  		return b
    48  	}, func(paths []byte) {
    49  		err := json.Unmarshal(paths, &beforeSuite)
    50  		Expect(err).ToNot(HaveOccurred())
    51  
    52  		externalIP = beforeSuite.ExampleDotCom
    53  	})
    54  
    55  	BeforeEach(func() {
    56  		if os.Getenv("GARDEN_TEST_ROOTFS") == "" {
    57  			Skip("GARDEN_TEST_ROOTFS undefined")
    58  		}
    59  	})
    60  
    61  	AfterEach(func() {
    62  		err := client.DestroyAndStop()
    63  		client.Cleanup()
    64  		Expect(err).NotTo(HaveOccurred())
    65  	})
    66  
    67  	SetDefaultEventuallyTimeout(5 * time.Second) // CI is sometimes slow
    68  
    69  	RegisterFailHandler(Fail)
    70  	RunSpecs(t, "Networking Suite")
    71  }