Skip to content

Instantly share code, notes, and snippets.

View williammartin's full-sized avatar

William Martin williammartin

View GitHub Profile
var _ = Describe("ginkgotcha", func() {
var number int = 10
It("is equal to 10", func() {
Expect(number).To(Equal(10))
})
When("the number is set to 42", func() {
BeforeEach(func() {
number = 42
@williammartin
williammartin / readall.go
Created June 20, 2019 09:44
Effective Ginkgo/Gomega dot import example
ginkgo.Describe("a command", func() {
var session *gexec.Session
ginkgo.Context("when it runs", func() {
ginkgo.BeforeEach(func() {
session = run()
})
ginkgo.It("exits successfully with a message", func() {
gomega.Eventually(session).Should(gexec.Exit(0))
@williammartin
williammartin / readall.go
Created June 20, 2019 09:44
Effective Ginkgo/Gomega helper example
func readAll(r io.Reader) []byte {
content, err := ioutil.ReadAll(r)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
return content
}
@williammartin
williammartin / beforeeach.go
Created June 20, 2019 09:43
Effective Ginkgo/Gomega BeforeEach Example
Describe("running the foo command", func() {
BeforeEach(func() {
args = append(args, "foo")
})
When("--help is passed", func() {
BeforeEach(func() {
args = append(args, "--help")
})
@williammartin
williammartin / hieararchy.go
Last active June 20, 2019 09:42
Effective Ginkgo/Gomega Example
var _ = Describe("running a binary", func() {
var (
args []string
session *Session
)
BeforeEach(func() {
args = []string{}
})

Given some disagreement on cloudfoundry/servicebroker#628 about the need for arbitrary data to describe the changes in some particular maintenance, I'd like to propose we tackle this problem in two steps.

What are the problem statements?

  1. As an application developer, I want to be able to update my own service instances when convenient to me, so that I can schedule downtime.
  2. As a platform operator, I want to be able to update out of date service instances, so I can manage offerings reasonably.

What is required to support this?

  1. There MUST be some indication that an update is available for a service instance
package acceptance_test
import (
"os/exec"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
)
func BeARunningProcess() types.GomegaMatcher {
return &BeARunningProcessMatcher{}
}
type BeARunningProcessMatcher struct {
actualPid int
}
func (matcher *BeARunningProcessMatcher) Match(actual interface{}) (bool, error) {
pid, ok := actual.(int)
package matcher_test
import (
"os/exec"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"golang.org/x/sys/unix"
)
@williammartin
williammartin / subreaper_reaping_main.go
Last active November 2, 2018 16:25
Subreaper reaping main
package main
import (
"fmt"
"os"
"os/exec"
"os/signal"
"time"
"github.com/williammartin/subreaper"