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

     1  package networking_test
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  
     7  	"github.com/cloudfoundry-incubator/garden"
     8  	. "github.com/onsi/ginkgo"
     9  )
    10  
    11  func checkConnection(container garden.Container, ip string, port int) error {
    12  	process, err := container.Run(garden.ProcessSpec{
    13  		User: "alice",
    14  		Path: "sh",
    15  		Args: []string{"-c", fmt.Sprintf("echo hello | nc -w1 %s %d", ip, port)},
    16  	}, garden.ProcessIO{Stdout: GinkgoWriter, Stderr: GinkgoWriter})
    17  	if err != nil {
    18  		return err
    19  	}
    20  
    21  	exitCode, err := process.Wait()
    22  	if err != nil {
    23  		return err
    24  	}
    25  
    26  	if exitCode == 0 {
    27  		return nil
    28  	} else {
    29  		return fmt.Errorf("Request failed. Process exited with code %d", exitCode)
    30  	}
    31  }
    32  
    33  func checkInternet(container garden.Container) error {
    34  	return checkConnection(container, externalIP.String(), 80)
    35  }
    36  
    37  // networking test utility functions
    38  func containerIfName(container garden.Container) string {
    39  	return ifNamePrefix(container) + "-1"
    40  }
    41  
    42  func hostIfName(container garden.Container) string {
    43  	return ifNamePrefix(container) + "-0"
    44  }
    45  
    46  func ifNamePrefix(container garden.Container) string {
    47  	return "w" + strconv.Itoa(GinkgoParallelNode()) + container.Handle()
    48  }