Esempio n. 1
0
	"github.com/ably/ably-go/ably"

	. "github.com/ably/ably-go/Godeps/_workspace/src/github.com/onsi/ginkgo"
	. "github.com/ably/ably-go/Godeps/_workspace/src/github.com/onsi/gomega"
)

var _ = Describe("ClientOptions", func() {
	var err error

	Context("when Key is valid", func() {
		var options *ably.ClientOptions

		BeforeEach(func() {
			options = &ably.ClientOptions{Key: "name:secret"}
			_, err = ably.NewRestClient(options)
		})

		It("parses it into a set of known parameters", func() {
			Expect(err).NotTo(HaveOccurred())
			Expect(options.KeyName()).To(Equal("name"))
			Expect(options.KeySecret()).To(Equal("secret"))
		})
	})

	Context("when Key is invalid", func() {
		BeforeEach(func() {
			_, err = ably.NewRestClient(&ably.ClientOptions{Key: "invalid"})
		})

		It("returns an error", func() {
Esempio n. 2
0
func TestAbly(t *testing.T) {
	t.Parallel()
	RegisterFailHandler(Fail)
	RunSpecs(t, "Ably Suite")
}

var (
	testApp *testutil.Sandbox
	client  *ably.RestClient
	channel *ably.RestChannel
)

var _ = BeforeSuite(func() {
	app, err := testutil.NewSandbox(nil)
	Expect(err).NotTo(HaveOccurred())
	testApp = app
})

var _ = BeforeEach(func() {
	cl, err := ably.NewRestClient(testApp.Options(nil))
	Expect(err).NotTo(HaveOccurred())
	client = cl
	channel = client.Channel("test")
})

var _ = AfterSuite(func() {
	err := testApp.Close()
	Expect(err).NotTo(HaveOccurred())
})
Esempio n. 3
0
	)

	Context("with a failing request", func() {
		var client *ably.RestClient

		BeforeEach(func() {
			server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				w.WriteHeader(404)
				w.Header().Set("Content-Type", "application/json")
				fmt.Fprintf(w, `{"message":"Not Found"}`)
			}))

			options := &ably.ClientOptions{NoTLS: true, HTTPClient: newHTTPClientMock(server)}

			var err error
			client, err = ably.NewRestClient(testApp.Options(options))
			Expect(err).NotTo(HaveOccurred())

			Expect(err).NotTo(HaveOccurred())
		})

		Describe("Get", func() {
			var data interface{}

			It("fails with a meaningful error", func() {
				_, err := client.Get("/any_path", data)
				Expect(err).To(HaveOccurred())

				e, ok := err.(*ably.Error)
				Expect(ok).To(BeTrue())
				Expect(e.Err.Error()).To(Equal("Not Found"))