Пример #1
0
				client = NewClient(&FailingConnectionProvider{})
			})

			It("should fail to connect", func() {
				err := client.Connect()
				Ω(err).Should(Equal(errors.New("nope!")))
			})
		})
	})

	Describe("The container lifecycle", func() {
		BeforeEach(func() {
			provider = NewFakeConnectionProvider(
				warden.Messages(
					&warden.CreateResponse{Handle: proto.String("foo")},
					&warden.StopResponse{},
					&warden.DestroyResponse{},
				),
				writeBuffer,
			)

			client = NewClient(provider)
			err := client.Connect()
			Ω(err).ShouldNot(HaveOccurred())
		})

		It("should be able to create, stop and destroy a container", func() {
			res, err := client.Create()
			Ω(err).ShouldNot(HaveOccurred())
			Ω(res.GetHandle()).Should(Equal("foo"))
Пример #2
0
	"math"

	"code.google.com/p/gogoprotobuf/proto"
	. "github.com/vito/gordon/test_helpers"
	"github.com/vito/gordon/warden"
)

var _ = Describe("Connection", func() {
	var (
		connection     *Connection
		writeBuffer    *bytes.Buffer
		wardenMessages []proto.Message
	)

	assertWriteBufferContains := func(messages ...proto.Message) {
		Ω(string(writeBuffer.Bytes())).Should(Equal(string(warden.Messages(messages...).Bytes())))
	}

	JustBeforeEach(func() {
		writeBuffer = bytes.NewBuffer([]byte{})

		fakeConn := &FakeConn{
			ReadBuffer:  warden.Messages(wardenMessages...),
			WriteBuffer: writeBuffer,
		}

		connection = New(fakeConn)
	})

	BeforeEach(func() {
		wardenMessages = []proto.Message{}