func killSession(session *gexec.Session) {
	if runtime.GOOS == "windows" {
		session.Kill().Wait()
	} else {
		session.Terminate().Wait()
	}
}
func TestLats(t *testing.T) {
	RegisterFailHandler(Fail)

	var metronSession *gexec.Session
	config = latsConfig.Load()

	BeforeSuite(func() {
		config.SaveMetronConfig()
		helpers.Initialize(config)
		metronSession = setupMetron()
	})

	AfterSuite(func() {
		metronSession.Kill().Wait()
	})

	RunSpecs(t, "Lats Suite")
}
示例#3
0
	"time"

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

	"github.com/dgodd/ssh-resource"
	"github.com/dgodd/ssh-resource/check"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
)

var _ = Describe("check", func() {
	var (
		command *exec.Cmd
		stdin   *bytes.Buffer
		session *gexec.Session

		expectedExitStatus int
	)

	BeforeEach(func() {
		stdin = &bytes.Buffer{}
		expectedExitStatus = 0

		command = exec.Command(checkPath)
		command.Stdin = stdin
	})

	JustBeforeEach(func() {
		var err error
		session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"testing"

	"github.com/onsi/ginkgo/config"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
)

func TestIntegrationTest(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "IntegrationTest Suite")
}

var metronSession *gexec.Session
var statsdInjectorSession *gexec.Session
var etcdRunner *etcdstorerunner.ETCDClusterRunner
var etcdPort int
var localIPAddress string

var pathToGoStatsdClient string

var _ = BeforeSuite(func() {
	pathToMetronExecutable, err := gexec.Build("metron")
	Expect(err).ShouldNot(HaveOccurred())

	pathToGoStatsdClient, err = gexec.Build("statsd-injector/tools/statsdGoClient")
	Expect(err).NotTo(HaveOccurred())

	command := exec.Command(pathToMetronExecutable, "--config=fixtures/metron.json", "--debug")
示例#5
0
func TestIntegration(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Integration Suite")
}

const natsPort = 24484
const SOCKET_PREFIX = "\n\n\n\n"
const instancesJsonPath = "fixtures/instances.json"
const wardenIdentifier = 56

var (
	task1InputListener  net.Listener
	task1StderrListener net.Listener
	newFile             *os.File
	etcdPort            int
	etcdRunner          *etcdstorerunner.ETCDClusterRunner
	deaAgentSession     *gexec.Session
	goRoutineSpawned    sync.WaitGroup
)

type messageHelperInterface interface {
	getTotalNumOfOutputMessages() int
	getValueOfValueMetric(string) float64
	getFirstLogMessageString() string
}

type messageHolder struct {
	messages []events.Envelope
	sync.RWMutex
}
示例#6
0
	"time"

	. "github.com/onsi/ginkgo"
	"github.com/onsi/ginkgo/config"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
)

const standardOutPriority = 14

var _ = Describe("SyslogWriter", func() {

	var sysLogWriter syslogwriter.Writer
	var dialer *net.Dialer
	var syslogServerSession *gexec.Session

	BeforeEach(func() {
		dialer = &net.Dialer{
			Timeout: 500 * time.Millisecond,
		}

		port := 9800 + config.GinkgoConfig.ParallelNode
		address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port))

		outputURL := &url.URL{Scheme: "syslog", Host: address}
		syslogServerSession = startSyslogServer(address)
		sysLogWriter, _ = syslogwriter.NewSyslogWriter(outputURL, "appId", dialer, 0)

		Eventually(func() error {
			err := sysLogWriter.Connect()
示例#7
0
	"github.com/concourse/s3-resource"
	"github.com/concourse/s3-resource/out"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"

	"github.com/nu7hatch/gouuid"
)

var _ = Describe("out", func() {
	var (
		command   *exec.Cmd
		stdin     *bytes.Buffer
		session   *gexec.Session
		sourceDir string

		expectedExitStatus int
	)

	BeforeEach(func() {
		var err error
		sourceDir, err = ioutil.TempDir("", "s3_out_integration_test")
		Ω(err).ShouldNot(HaveOccurred())

		stdin = &bytes.Buffer{}
		expectedExitStatus = 0

		command = exec.Command(outPath, sourceDir)
		command.Stdin = stdin
	})
import (
	"fmt"
	"io/ioutil"
	"os"
	"sync"
	"time"

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

var _ = Describe("MultipleClientsSingleBroker", func() {
	var (
		URL     string
		session *gexec.Session
	)

	BeforeEach(func() {
		var err error
		tmpDir, err = ioutil.TempDir("/tmp", "systemtalaria")
		Expect(err).ToNot(HaveOccurred())
		URL, session = startTalaria(tmpDir)
	})

	AfterEach(func() {
		session.Kill()
		session.Wait("10s", "100ms")

		Expect(os.RemoveAll(tmpDir)).To(Succeed())
	})
			key := DrainKey(appID, badURL)
			AddETCDNode(etcdAdapter, key, badURL)

			receivedMessageBytes := []byte{}
			Eventually(receivedChan, 20).Should(Receive(&receivedMessageBytes))
			receivedMessage := DecodeProtoBufLogMessage(receivedMessageBytes)

			Expect(receivedMessage.GetAppId()).To(Equal(appID))
			Expect(string(receivedMessage.GetMessage())).To(ContainSubstring("Err: Resolving host failed"))
			Expect(string(receivedMessage.GetMessage())).To(ContainSubstring(badURL))
		}
	})

	Context("when connecting over TCP", func() {
		var (
			syslogDrainAddress = fmt.Sprintf("%s:%d", localIPAddress, syslogPort)
			drainSession       *gexec.Session
		)

		Context("when forwarding to an unencrypted syslog:// endpoint", func() {
			BeforeEach(func() {
				drainSession = StartUnencryptedTCPServer(pathToTCPEchoServer, syslogDrainAddress)
			})

			AfterEach(func() {
				drainSession.Kill().Wait()
			})

			It("forwards log messages to a syslog", func() {
				syslogDrainURL := "syslog://" + syslogDrainAddress
				key := DrainKey(appID, syslogDrainURL)
				AddETCDNode(etcdAdapter, key, syslogDrainURL)
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gexec"
)

const (
	APP_ID                            = "1234"
	AUTH_TOKEN                        = "bearer iAmAnAdmin"
	SUBSCRIPTION_ID                   = "firehose-subscription-1"
	TRAFFIC_CONTROLLER_DROPSONDE_PORT = 4566
)

var (
	trafficControllerExecPath string
	trafficControllerSession  *gexec.Session
	gnatsdSession             *gexec.Session
	etcdRunner                *etcdstorerunner.ETCDClusterRunner
	etcdPort                  int
	localIPAddress            string
	fakeDoppler               *fake_doppler.FakeDoppler
	configFile                string
)

func TestIntegrationTest(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Traffic Controller Integration Suite")
}

var _ = BeforeSuite(func() {
	killEtcdCmd := exec.Command("pkill", "etcd")
	killEtcdCmd.Run()
	setupEtcdAdapter()
	setupDopplerInEtcd()
示例#11
0
	"github.com/apoydence/talaria/logging"
	"github.com/hashicorp/consul/api"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gexec"
)

func TestKvstore(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Kvstore Suite")
}

var (
	consulSession *gexec.Session
	tmpDir        string
	consulClient  *api.Client
)

var _ = BeforeSuite(func() {
	logging.SetLevel(logging.CRITICAL)
	consulPath, err := gexec.Build("github.com/hashicorp/consul")
	Expect(err).ToNot(HaveOccurred())

	tmpDir, err = ioutil.TempDir("", "consul")
	Expect(err).ToNot(HaveOccurred())

	consulCmd := exec.Command(consulPath, "agent", "-server", "-bootstrap-expect", "1", "-data-dir", tmpDir, "-bind", "127.0.0.1")
	consulSession, err = gexec.Start(consulCmd, nil, nil)
	Expect(err).ToNot(HaveOccurred())
	Consistently(consulSession).ShouldNot(gexec.Exit())
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gexec"
	"github.com/pivotal-cf-experimental/opentsdb-firehose-nozzle/poster"
	"github.com/pivotal-cf-experimental/opentsdb-firehose-nozzle/util"
)

var (
	fakeFirehoseInputChan chan *events.Envelope
	fakeOpenTSDBChan      chan []byte
)

var _ = Describe("OpentsdbFirehoseNozzle", func() {
	var (
		fakeUAA      *http.Server
		fakeFirehose *http.Server
		fakeOpentsdb *http.Server

		nozzleSession *gexec.Session
	)

	BeforeEach(func() {
		fakeFirehoseInputChan = make(chan *events.Envelope)
		fakeOpenTSDBChan = make(chan []byte)

		fakeUAA = &http.Server{
			Addr:    ":8084",
			Handler: http.HandlerFunc(fakeUAAHandler),
		}
		fakeFirehose = &http.Server{
			Addr:    ":8086",
			Handler: http.HandlerFunc(fakeFirehoseHandler),
示例#13
0
	Eventually(session).Should(gbytes.Say("garagepi starting"))
	return session
}

var _ = Describe("GaragepiExecutable", func() {
	var (
		args []string
	)

	BeforeEach(func() {
		args = []string{}
	})

	Describe("long-running operation", func() {
		var (
			session *gexec.Session
		)

		AfterEach(func() {
			session.Terminate()
		})

		Describe("UI", func() {
			var page *agouti.Page

			BeforeEach(func() {
				var err error
				page, err = agoutiDriver.NewPage()
				Expect(err).NotTo(HaveOccurred())
			})
示例#14
0
	"path/filepath"

	"github.com/concourse/s3-resource"
	"github.com/concourse/s3-resource/in"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
)

var _ = Describe("in", func() {
	var (
		command *exec.Cmd
		stdin   *bytes.Buffer
		session *gexec.Session
		destDir string

		expectedExitStatus int
	)

	BeforeEach(func() {
		var err error
		destDir, err = ioutil.TempDir("", "s3_in_integration_test")
		Ω(err).ShouldNot(HaveOccurred())

		stdin = &bytes.Buffer{}
		expectedExitStatus = 0

		command = exec.Command(inPath, destDir)
		command.Stdin = stdin
	})
package scripts_test

import (
	"os/exec"
	"strings"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
)

var _ = Describe("ExtractTFVarsFromTFState", func() {

	var (
		cmdInput string
		session  *gexec.Session
	)

	JustBeforeEach(func() {
		command := exec.Command("./extract_tf_vars_from_terraform_state.rb")
		command.Stdin = strings.NewReader(cmdInput)

		var err error
		session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
		Expect(err).ToNot(HaveOccurred())
	})

	Context("with a valid tfstate file", func() {
		BeforeEach(func() {
			cmdInput = `
{
	"runtime"
	"time"
)

func TestIntegrationTest(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "End-to-end Integration Test Suite")
}

var (
	LocalIPAddress string

	etcdRunner  *etcdstorerunner.ETCDClusterRunner
	etcdAdapter storeadapter.StoreAdapter

	metronExecutablePath            string
	dopplerExecutablePath           string
	trafficControllerExecutablePath string

	metronSession  *gexec.Session
	dopplerSession *gexec.Session
	tcSession      *gexec.Session
)

var _ = BeforeSuite(func() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	etcdRunner = etcdstorerunner.NewETCDClusterRunner(49623, 1, nil)
	etcdRunner.Start()
	etcdAdapter = etcdRunner.Adapter(nil)
	metronExecutablePath = buildComponent("metron")
	dopplerExecutablePath = buildComponent("doppler")
	trafficControllerExecutablePath = buildComponent("trafficcontroller")
示例#17
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"os/exec"
	"testing"

	"github.com/cloudfoundry/dropsonde/factories"
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/cloudfoundry/storeadapter/storerunner/etcdstorerunner"
	"github.com/gogo/protobuf/proto"
	"github.com/nu7hatch/gouuid"
	"github.com/onsi/ginkgo/config"
	"github.com/onsi/gomega/gexec"
)

var metronSession *gexec.Session
var etcdRunner *etcdstorerunner.ETCDClusterRunner
var etcdPort int
var pathToMetronExecutable string

func TestMetrics(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Metrics Suite")
}

var _ = BeforeSuite(func() {
	var err error
	pathToMetronExecutable, err = gexec.Build("metron", "-race")
	Expect(err).ShouldNot(HaveOccurred())

	etcdPort = 5800 + (config.GinkgoConfig.ParallelNode-1)*10
	"github.com/onsi/gomega/gexec"
)

var _ = Describe("Upgrading RabbitMQ", func() {
	execBin := func(args ...string) *gexec.Session {
		args = append(args, "-timeout=1s")
		cmd := exec.Command(binPath, args...)
		session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
		Expect(err).ToNot(HaveOccurred())
		return session
	}

	var (
		args    []string
		session *gexec.Session

		tmpDir  string
		tmpFile string
	)

	itExitsWithZero := func() {
		It("exits with a zero exit code", func() {
			Eventually(session).Should(gexec.Exit(0))
		})
	}

	itExitsWithNonZero := func() {
		It("exits with a non-zero exit code", func() {
			Eventually(session).Should(gexec.Exit())
			Expect(session.ExitCode()).NotTo(BeZero())
		})
示例#19
0
			outputURL, _ := url.Parse("https://localhost")
			_, err := syslogwriter.NewTlsWriter(outputURL, "appId", false, dialer, ioTimeout)
			Expect(err).To(HaveOccurred())
		})

		It("returns an error if the provided dialer is nil", func() {
			outputURL, _ := url.Parse("syslog-tls://localhost")
			_, err := syslogwriter.NewTlsWriter(outputURL, "appId", false, nil, ioTimeout)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("cannot construct a writer with a nil dialer"))
		})
	})

	Describe("Write", func() {
		const standardOutPriority = 14
		var syslogServerSession *gexec.Session
		var syslogWriter syslogwriter.Writer
		var skipCertVerify bool

		BeforeEach(func() {
			skipCertVerify = true
		})

		JustBeforeEach(func() {
			dialer = &net.Dialer{
				Timeout: time.Second,
			}

			var err error
			port := 9900 + config.GinkgoConfig.ParallelNode
			address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port))
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
)

func TestBenchmark(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Benchmark Suite")
}

var (
	dopplerSession *gexec.Session
	localIPAddress string
	etcdRunner     *etcdstorerunner.ETCDClusterRunner
	etcdAdapter    storeadapter.StoreAdapter

	pathToDopplerExec string
)

var _ = BeforeSuite(func() {
	etcdPort := 5555
	etcdRunner = etcdstorerunner.NewETCDClusterRunner(etcdPort, 1, nil)
	etcdRunner.Start()
	etcdAdapter = etcdRunner.Adapter(nil)

	var err error
	pathToDopplerExec, err = gexec.Build("doppler")
	Expect(err).NotTo(HaveOccurred())
})
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gexec"
	"github.com/pivotal-cf/brokerapi"
)

var _ = Describe("CfExampleBroker", func() {

	var (
		session *gexec.Session
	)

	BeforeEach(func() {
		args := []string{}
		session = execBin(args...)
		time.Sleep(1 * time.Second)
	})

	AfterEach(func() {
		session.Kill()
	})

	provisionRequest := func(provisionDetails brokerapi.ProvisionDetails) (*http.Response, error) {
		client := &http.Client{}
		path := fmt.Sprintf("http://localhost:3000/v2/service_instances/%s", provisionDetails.ID)
import (
	"bytes"
	"encoding/json"
	"path/filepath"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
	"github.com/pivotal-cf/redis-cpu/metrics"
)

var _ = Describe("redis-cpu", func() {
	var (
		session    *gexec.Session
		configPath string
	)

	BeforeEach(func() {
		configPath = filepath.Join(".", "assets", "redis.conf")
	})

	JustBeforeEach(func() {
		session = runBin(configPath)
	})

	var decodeJson = func(session *gexec.Session) metrics.Metric {
		var m metrics.Metric
		err := json.NewDecoder(bytes.NewReader(session.Out.Contents())).Decode(&m)
		Expect(err).ToNot(HaveOccurred())
		return m
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gexec"
	"github.com/sclevine/agouti"

	"testing"
)

func TestIntegration(t *testing.T) {
	RegisterFailHandler(Fail)
	SetDefaultEventuallyTimeout(time.Second * 5)
	RunSpecs(t, "Integration Suite")
}

var (
	executablePath    string
	runningExecutable *gexec.Session
	buildsDir         string
	agoutiDriver      *agouti.WebDriver
)

var _ = BeforeSuite(func() {
	var err error
	executablePath, err = gexec.Build("github.com/craigfurman/woodhouse-ci")
	Expect(err).NotTo(HaveOccurred())

	if os.Getenv("HEADLESS") == "true" {
		agoutiDriver = agouti.PhantomJS()
	} else {
		agoutiDriver = agouti.ChromeDriver()
	}
	Expect(agoutiDriver.Start()).To(Succeed())
})
			Expect(err).ToNot(HaveOccurred())
			defer connection.Close()

			statsdmsg := []byte("fake-origin.test.counter:42|c")
			_, err = connection.Write(statsdmsg)
			Expect(err).ToNot(HaveOccurred())

			expected := basicValueMetric("test.counter", 42, "counter")
			Eventually(getValueMetric).Should(Equal(expected))
		}, 5)
	})

	Context("with a Go statsd client", func() {
		var (
			clientInput   io.WriteCloser
			clientSession *gexec.Session
			err           error
		)

		BeforeEach(func() {
			clientCommand := exec.Command(pathToGoStatsdClient, "51162")

			clientInput, err = clientCommand.StdinPipe()
			Expect(err).NotTo(HaveOccurred())

			clientSession, err = gexec.Start(clientCommand, GinkgoWriter, GinkgoWriter)
			Expect(err).NotTo(HaveOccurred())
		})

		AfterEach(func() {
			clientInput.Close()
示例#25
0
func itWorksWithBranch(branchName string) {
	Context("when the branch name is "+branchName, func() {

		var gitRepo string
		var bareGitRepo string
		var sourceDir string

		var outResponse out.OutResponse
		var outRequest out.OutRequest

		BeforeEach(func() {
			var err error
			gitRepo, err = ioutil.TempDir("", "git-repo")
			Ω(err).ShouldNot(HaveOccurred())

			bareGitRepo, err = ioutil.TempDir("", "bare-git-repo")
			Ω(err).ShouldNot(HaveOccurred())

			sourceDir, err = ioutil.TempDir("", "source-dir")
			Ω(err).ShouldNot(HaveOccurred())

			setupGitRepo(gitRepo)

			bareGitSetup := exec.Command("bash", "-e", "-c", fmt.Sprintf(`
			git clone %s --bare .
		`, gitRepo))
			bareGitSetup.Dir = bareGitRepo

			err = bareGitSetup.Run()
			Ω(err).ShouldNot(HaveOccurred())
		})

		AfterEach(func() {
			err := os.RemoveAll(bareGitRepo)
			Ω(err).ShouldNot(HaveOccurred())

			err = os.RemoveAll(gitRepo)
			Ω(err).ShouldNot(HaveOccurred())

			err = os.RemoveAll(sourceDir)
			Ω(err).ShouldNot(HaveOccurred())
		})

		Context("when the config is incomplete", func() {
			var session *gexec.Session

			BeforeEach(func() {
				outRequest = out.OutRequest{
					Source: out.Source{
						URI:        bareGitRepo,
						Branch:     branchName,
						Pool:       "lock-pool",
						RetryDelay: 100 * time.Millisecond,
					},
					Params: out.OutParams{
						Acquire: true,
					},
				}
			})

			JustBeforeEach(func() {
				session = runOut(outRequest, sourceDir)
				Eventually(session).Should(gexec.Exit(1))
			})

			Context("when the uri isn't set", func() {
				BeforeEach(func() {
					outRequest.Source.URI = ""
				})

				It("complains about it", func() {
					errorMessages := string(session.Err.Contents())

					Ω(errorMessages).Should(ContainSubstring("invalid payload (missing uri)"))
				})
			})

			Context("when the pool isn't set", func() {
				BeforeEach(func() {
					outRequest.Source.Pool = ""
				})

				It("complains about it", func() {
					errorMessages := string(session.Err.Contents())

					Ω(errorMessages).Should(ContainSubstring("invalid payload (missing pool)"))
				})
			})

			Context("when the branch isn't set", func() {
				BeforeEach(func() {
					outRequest.Source.Branch = ""
				})

				It("complains about it", func() {
					errorMessages := string(session.Err.Contents())

					Ω(errorMessages).Should(ContainSubstring("invalid payload (missing branch)"))
				})
			})

			Context("when the branch isn't set", func() {
				BeforeEach(func() {
					outRequest.Params = out.OutParams{}
				})

				It("complains about it", func() {
					errorMessages := string(session.Err.Contents())

					Ω(errorMessages).Should(ContainSubstring("invalid payload (missing acquire, release, remove, or add)"))
				})
			})
		})

		Context("When acquiring a lock", func() {
			BeforeEach(func() {
				outRequest = out.OutRequest{
					Source: out.Source{
						URI:        bareGitRepo,
						Branch:     branchName,
						Pool:       "lock-pool",
						RetryDelay: 100 * time.Millisecond,
					},
					Params: out.OutParams{
						Acquire: true,
					},
				}

				session := runOut(outRequest, sourceDir)
				Eventually(session).Should(gexec.Exit(0))

				err := json.Unmarshal(session.Out.Contents(), &outResponse)
				Ω(err).ShouldNot(HaveOccurred())
			})

			It("moves a lock to claimed", func() {
				version := getVersion(bareGitRepo, "origin/"+branchName)

				reCloneRepo, err := ioutil.TempDir("", "git-version-repo")
				Ω(err).ShouldNot(HaveOccurred())

				defer os.RemoveAll(reCloneRepo)

				reClone := exec.Command("git", "clone", "--branch", branchName, bareGitRepo, ".")
				reClone.Dir = reCloneRepo
				err = reClone.Run()
				Ω(err).ShouldNot(HaveOccurred())

				claimedFiles, err := ioutil.ReadDir(filepath.Join(reCloneRepo, "lock-pool", "claimed"))
				Ω(err).ShouldNot(HaveOccurred())

				Ω(len(claimedFiles)).Should(Equal(2))

				var lockFile string
				for _, file := range claimedFiles {
					filename := filepath.Base(file.Name())
					if filename != ".gitkeep" {
						lockFile = filename
					}
				}

				Ω(outResponse).Should(Equal(out.OutResponse{
					Version: version,
					Metadata: []out.MetadataPair{
						{Name: "lock_name", Value: lockFile},
						{Name: "pool_name", Value: "lock-pool"},
					},
				}))
			})
		})

		Context("when there are no locks to be claimed", func() {
			var session *gexec.Session
			var claimAllLocksDir string

			BeforeEach(func() {
				var err error

				outRequest = out.OutRequest{
					Source: out.Source{
						URI:        bareGitRepo,
						Branch:     branchName,
						Pool:       "lock-pool",
						RetryDelay: 1 * time.Second,
					},
					Params: out.OutParams{
						Acquire: true,
					},
				}

				claimAllLocksDir, err = ioutil.TempDir("", "claiming-locks")
				Ω(err).ShouldNot(HaveOccurred())

				claimAllLocks := exec.Command("bash", "-e", "-c", fmt.Sprintf(`
				git clone --branch %s %s .

				git config user.email "ginkgo@localhost"
				git config user.name "Ginkgo Local"

				git mv lock-pool/unclaimed/* lock-pool/claimed/
				git commit -am "claiming all locks"
				git push
			`, branchName, bareGitRepo))

				claimAllLocks.Stdout = GinkgoWriter
				claimAllLocks.Stderr = GinkgoWriter
				claimAllLocks.Dir = claimAllLocksDir

				err = claimAllLocks.Run()
				Ω(err).ShouldNot(HaveOccurred())

				session = runOut(outRequest, sourceDir)
			})

			AfterEach(func() {
				err := os.RemoveAll(claimAllLocksDir)
				Ω(err).ShouldNot(HaveOccurred())
			})

			It("retries until a lock can be claimed", func() {
				Consistently(session, 2*time.Second).ShouldNot(gexec.Exit(0))

				releaseLock := exec.Command("bash", "-e", "-c", fmt.Sprint(`
				git mv lock-pool/claimed/some-lock lock-pool/unclaimed/some-lock
				git commit -am "unclaiming some-lock"
				git push
			`))

				releaseLock.Dir = claimAllLocksDir

				err := releaseLock.Run()
				Ω(err).ShouldNot(HaveOccurred())

				Eventually(session, 2*time.Second).Should(gexec.Exit(0))

				err = json.Unmarshal(session.Out.Contents(), &outResponse)
				Ω(err).ShouldNot(HaveOccurred())

				Ω(outResponse).Should(Equal(out.OutResponse{
					Version: out.Version{
						Ref: outResponse.Version.Ref,
					},
					Metadata: []out.MetadataPair{
						{Name: "lock_name", Value: "some-lock"},
						{Name: "pool_name", Value: "lock-pool"},
					},
				}))
			})
		})

		Context("When removing a lock", func() {
			var myLocksGetDir string
			var outReleaseRequest out.OutRequest
			var outReleaseResponse out.OutResponse

			BeforeEach(func() {
				outRequest = out.OutRequest{
					Source: out.Source{
						URI:    bareGitRepo,
						Branch: branchName,
						Pool:   "lock-pool",
					},
					Params: out.OutParams{
						Acquire: true,
					},
				}

				session := runOut(outRequest, sourceDir)
				Eventually(session).Should(gexec.Exit(0))

				err := json.Unmarshal(session.Out.Contents(), &outResponse)
				Ω(err).ShouldNot(HaveOccurred())
			})

			JustBeforeEach(func() {
				var err error

				myLocksGetDir, err = ioutil.TempDir("", "my-locks")
				Ω(err).ShouldNot(HaveOccurred())

				jsonIn := fmt.Sprintf(`
				{
					"source": {
						"uri": "%s",
						"branch": "%s",
						"pool": "lock-pool"
					},
					"version": {
						"ref": "%s"
					}
				}`, bareGitRepo, branchName, string(outResponse.Version.Ref))

				runIn(jsonIn, filepath.Join(myLocksGetDir, "lock-step-name"), 0)

				outReleaseRequest = out.OutRequest{
					Source: out.Source{
						URI:    bareGitRepo,
						Branch: branchName,
						Pool:   "lock-pool",
					},
					Params: out.OutParams{
						Remove: "lock-step-name",
					},
				}

				session := runOut(outReleaseRequest, myLocksGetDir)
				Eventually(session).Should(gexec.Exit(0))

				err = json.Unmarshal(session.Out.Contents(), &outReleaseResponse)
				Ω(err).ShouldNot(HaveOccurred())
			})

			AfterEach(func() {
				err := os.RemoveAll(myLocksGetDir)
				Ω(err).ShouldNot(HaveOccurred())
			})

			It("removes the lock from the pool", func() {
				version := getVersion(bareGitRepo, "origin/"+branchName)

				reCloneRepo, err := ioutil.TempDir("", "git-version-repo")
				Ω(err).ShouldNot(HaveOccurred())

				defer os.RemoveAll(reCloneRepo)

				reClone := exec.Command("git", "clone", "--branch", branchName, bareGitRepo, ".")
				reClone.Dir = reCloneRepo
				err = reClone.Run()
				Ω(err).ShouldNot(HaveOccurred())

				claimedFiles, err := ioutil.ReadDir(filepath.Join(reCloneRepo, "lock-pool", "claimed"))
				Ω(err).ShouldNot(HaveOccurred())

				Ω(len(claimedFiles)).Should(Equal(1))

				unclaimedFiles, err := ioutil.ReadDir(filepath.Join(reCloneRepo, "lock-pool", "unclaimed"))
				Ω(err).ShouldNot(HaveOccurred())

				Ω(len(unclaimedFiles)).Should(Equal(2))

				var removedLockName string
				for _, metaDataPair := range outResponse.Metadata {
					if metaDataPair.Name == "lock_name" {
						removedLockName = metaDataPair.Value
					}
				}

				Ω(outReleaseResponse).Should(Equal(out.OutResponse{
					Version: version,
					Metadata: []out.MetadataPair{
						{Name: "lock_name", Value: removedLockName},
						{Name: "pool_name", Value: "lock-pool"},
					},
				}))
			})
		})

		Context("When releasing a lock", func() {
			var myLocksGetDir string
			var outReleaseRequest out.OutRequest
			var outReleaseResponse out.OutResponse

			BeforeEach(func() {
				outRequest = out.OutRequest{
					Source: out.Source{
						URI:    bareGitRepo,
						Branch: branchName,
						Pool:   "lock-pool",
					},
					Params: out.OutParams{
						Acquire: true,
					},
				}

				session := runOut(outRequest, sourceDir)
				Eventually(session).Should(gexec.Exit(0))

				err := json.Unmarshal(session.Out.Contents(), &outResponse)
				Ω(err).ShouldNot(HaveOccurred())
			})

			JustBeforeEach(func() {
				var err error

				myLocksGetDir, err = ioutil.TempDir("", "my-locks")
				Ω(err).ShouldNot(HaveOccurred())

				jsonIn := fmt.Sprintf(`
				{
					"source": {
						"uri": "%s",
						"branch": "%s",
						"pool": "lock-pool"
					},
					"version": {
						"ref": "%s"
					}
				}`, bareGitRepo, branchName, string(outResponse.Version.Ref))

				runIn(jsonIn, filepath.Join(myLocksGetDir, "lock-step-name"), 0)

				outReleaseRequest = out.OutRequest{
					Source: out.Source{
						URI:    bareGitRepo,
						Branch: branchName,
						Pool:   "lock-pool",
					},
					Params: out.OutParams{
						Release: "lock-step-name",
					},
				}

				session := runOut(outReleaseRequest, myLocksGetDir)
				Eventually(session).Should(gexec.Exit(0))

				err = json.Unmarshal(session.Out.Contents(), &outReleaseResponse)
				Ω(err).ShouldNot(HaveOccurred())
			})

			AfterEach(func() {
				err := os.RemoveAll(myLocksGetDir)
				Ω(err).ShouldNot(HaveOccurred())
			})

			It("moves the lock to unclaimed", func() {
				version := getVersion(bareGitRepo, "origin/"+branchName)

				reCloneRepo, err := ioutil.TempDir("", "git-version-repo")
				Ω(err).ShouldNot(HaveOccurred())

				defer os.RemoveAll(reCloneRepo)

				reClone := exec.Command("git", "clone", "--branch", branchName, bareGitRepo, ".")
				reClone.Dir = reCloneRepo
				err = reClone.Run()
				Ω(err).ShouldNot(HaveOccurred())

				claimedFiles, err := ioutil.ReadDir(filepath.Join(reCloneRepo, "lock-pool", "claimed"))
				Ω(err).ShouldNot(HaveOccurred())

				Ω(len(claimedFiles)).Should(Equal(1))

				unclaimedFiles, err := ioutil.ReadDir(filepath.Join(reCloneRepo, "lock-pool", "unclaimed"))
				Ω(err).ShouldNot(HaveOccurred())

				Ω(len(unclaimedFiles)).Should(Equal(3))

				var releasedLockName string
				for _, metaDataPair := range outResponse.Metadata {
					if metaDataPair.Name == "lock_name" {
						releasedLockName = metaDataPair.Value
					}
				}

				Ω(outReleaseResponse).Should(Equal(out.OutResponse{
					Version: version,
					Metadata: []out.MetadataPair{
						{Name: "lock_name", Value: releasedLockName},
						{Name: "pool_name", Value: "lock-pool"},
					},
				}))
			})
		})

		Context("when adding a lock to the pool", func() {
			var lockToAddDir string
			var cloneDir string

			BeforeEach(func() {
				lockToAddDir, err := ioutil.TempDir("", "lock-to-add")
				Ω(err).ShouldNot(HaveOccurred())

				cloneDir, err = ioutil.TempDir("", "clone")
				Ω(err).ShouldNot(HaveOccurred())

				taskDir := filepath.Join(lockToAddDir, "task-name")
				err = os.Mkdir(taskDir, 0755)

				err = ioutil.WriteFile(filepath.Join(taskDir, "metadata"), []byte("hello"), 0555)
				Ω(err).ShouldNot(HaveOccurred())

				err = ioutil.WriteFile(filepath.Join(taskDir, "name"), []byte("added-lock-name"), 0555)
				Ω(err).ShouldNot(HaveOccurred())

				outRequest = out.OutRequest{
					Source: out.Source{
						URI:        bareGitRepo,
						Branch:     branchName,
						Pool:       "lock-pool",
						RetryDelay: 100 * time.Millisecond,
					},
					Params: out.OutParams{
						Add: "task-name",
					},
				}

				session := runOut(outRequest, lockToAddDir)
				Eventually(session).Should(gexec.Exit(0))

				err = json.Unmarshal(session.Out.Contents(), &outResponse)
				Ω(err).ShouldNot(HaveOccurred())
			})

			AfterEach(func() {
				err := os.RemoveAll(lockToAddDir)
				Ω(err).ShouldNot(HaveOccurred())

				err = os.RemoveAll(cloneDir)
				Ω(err).ShouldNot(HaveOccurred())
			})

			It("adds the new lock", func() {
				clone := exec.Command("git", "clone", "--branch", branchName, bareGitRepo, ".")
				clone.Dir = cloneDir
				err := clone.Run()
				Ω(err).ShouldNot(HaveOccurred())

				lockPath := filepath.Join(cloneDir, "lock-pool", "unclaimed", "added-lock-name")

				Ω(lockPath).Should(BeARegularFile())
				contents, err := ioutil.ReadFile(lockPath)
				Ω(err).ShouldNot(HaveOccurred())

				Ω(string(contents)).Should(Equal("hello"))
			})
		})

		Context("when 2 processes are acquiring a lock at the same time", func() {
			var sessionOne *gexec.Session
			var sessionTwo *gexec.Session
			var gitServerSession *gexec.Session

			var sessionOneDir string
			var sessionTwoDir string
			var claimLockDir string

			var exitedCounter uint64

			BeforeEach(func() {
				var err error
				sessionOneDir, err = ioutil.TempDir("", "session-one")
				Ω(err).ShouldNot(HaveOccurred())

				sessionTwoDir, err = ioutil.TempDir("", "session-two")
				Ω(err).ShouldNot(HaveOccurred())

				claimLockDir, err = ioutil.TempDir("", "claiming-locks")
				Ω(err).ShouldNot(HaveOccurred())

				gitPort := GinkgoParallelNode() + 9418
				gitURI := fmt.Sprintf("git://*****:*****@localhost"
				git config user.name "Ginkgo Local"

				git mv lock-pool/unclaimed/some-lock lock-pool/claimed/
				git commit -am "claiming a lock"
				git push
			`, branchName, bareGitRepo))

					claimOneLock.Stdout = GinkgoWriter
					claimOneLock.Stderr = GinkgoWriter
					claimOneLock.Dir = claimLockDir

					err = claimOneLock.Run()
					Ω(err).ShouldNot(HaveOccurred())

				})

				It("does not acquire the same lock", func() {
					Eventually(func() uint64 {
						return exitedCounter
					}, 5*time.Second).Should(Equal(uint64(1)))
					Consistently(func() uint64 {
						return exitedCounter
					}, 2*time.Second).Should(Equal(uint64(1)))

					sessionOne.Terminate().Wait()
					sessionTwo.Terminate().Wait()

					Ω(sessionOne.Err).ShouldNot(gbytes.Say("err"))
					Ω(sessionTwo.Err).ShouldNot(gbytes.Say("err"))
				})
			})
		})
	})
}
示例#26
0
func (emitter *ByteEmitter) Read(p []byte) (n int, err error) {
	if emitter.written >= emitter.length {
		return 0, io.EOF
	}
	time.Sleep(time.Millisecond)
	p[0] = 0xF1
	emitter.written++
	return 1, nil
}

var _ = Describe("File server", func() {
	var (
		port            int
		address         string
		servedDirectory string
		session         *gexec.Session
		err             error
	)

	start := func(extras ...string) *gexec.Session {
		args := append(
			extras,
			"-staticDirectory", servedDirectory,
			"-address", fmt.Sprintf("localhost:%d", port),
			"-skipCertVerify",
		)

		session, err = gexec.Start(exec.Command(fileServerBinary, args...), GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())
	"net"
	"net/http"
	"net/http/httptest"
	"os/exec"
	"strings"
	"time"

	"github.com/onsi/gomega/gexec"

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

var _ = Describe("Proxying consul requests", func() {
	var (
		session *gexec.Session
		port    string
	)

	BeforeEach(func() {
		var err error
		port, err = openPort()
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		session.Terminate().Wait()
	})

	Context("main", func() {
		It("returns 1 when the consul url is malformed", func() {
			command := exec.Command(pathToConsumer, "--port", port, "--consul-url", "%%%%%%%%%%", "--path-to-check-a-record", pathToCheckARecord)
示例#28
0
	Context("with TLS enabled", func() {
		It("advertises udp, tcp, and ws endpoints", func() {
			node, err := etcdAdapter.Get("/doppler/meta/z1/doppler_z1/0")
			Expect(err).ToNot(HaveOccurred())

			expectedJSON := fmt.Sprintf(
				`{"version": 1, "endpoints":["udp://%[1]s:8765", "tcp://%[1]s:4321", "ws://%[1]s:4567", "tls://%[1]s:8766"]}`,
				localIPAddress)

			Expect(node.Value).To(MatchJSON(expectedJSON))
		})
	})

	Context("with TLS disabled", func() {
		var (
			dopplerSessionWithoutTLS *gexec.Session
			err                      error
		)

		BeforeEach(func() {
			command := exec.Command(pathToDopplerExec, "--config=fixtures/doppler_without_tls.json")
			dopplerSessionWithoutTLS, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
			Expect(err).NotTo(HaveOccurred())
			Eventually(dopplerSessionWithoutTLS.Out, 3).Should(gbytes.Say("Startup: doppler server started"))

			Eventually(func() error {
				_, err := etcdAdapter.Get("/doppler/meta/z1/doppler_z1/1")
				return err
			}, time.Second+config.HeartbeatInterval).ShouldNot(HaveOccurred())
		})

		AfterEach(func() {
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gexec"
	"github.com/pivotal-golang/lager/lagertest"
)

var _ = Describe("Sandbox Consistency", func() {
	var (
		session        *gexec.Session
		ducatiCmd      *exec.Cmd
		address        string
		containerID    string
		vni            int
		sandboxName    string
		sandboxRepoDir string
		spaceID        string
		appID          string
		networkID      string

		logger *lagertest.TestLogger
		// sandboxRepo        namespace.Repository
		containerRepo      namespace.Repository
		containerNamespace namespace.Namespace

		configFilePath string
	)

	BeforeEach(func() {
		var err error
		address = fmt.Sprintf("127.0.0.1:%d", 4001+GinkgoParallelNode())
		sandboxRepoDir, err = ioutil.TempDir("", "sandbox")
		Expect(err).NotTo(HaveOccurred())
var testBinaryPath string

var _ = BeforeSuite(func() {
	var err error
	testBinaryPath, err = gexec.Build("github.com/logsearch/nats-to-syslog")
	handleError(err)
})

var _ = AfterSuite(func() {
	gexec.CleanupBuildArtifacts()
})

var _ = Describe("NatsToSyslog", func() {
	var (
		gnatsd       *gexec.Session
		natsClient   *nats.Conn
		syslogServer *net.TCPListener
	)

	BeforeEach(func() {
		gnatsd = startGNATSd()

		var err error
		natsClient, err = nats.Connect("nats://*****:*****@127.0.0.1:4567")
		handleError(err)

		syslogServer = startSyslogServer()
	})

	It("forwards NATS messages to syslog", func() {
		testBinary := exec.Command(testBinaryPath, "-nats-uri", "nats://*****:*****@127.0.0.1:4567", "-syslog-endpoint", "localhost:6789", "-nats-subject", "testSubject", "-debug", "true")