Describe("Request()", func() {

		var sessionsResource *sessions.Resource = nil
		var usersResource *users.Resource = nil
		BeforeEach(func() {

			// configure test server
			ctx := context.New()

			renderer := renderer.New(&renderer.Options{
				IndentJSON: true,
			}, renderer.JSON)

			testMiddleware := test_helpers.NewTestMiddleware()
			testContextMiddleware := test_helpers.NewTestContextMiddleware()
			testResource := test_helpers.NewTestResource(ctx, renderer, &test_helpers.TestResourceOptions{})

			// create test server
			ts = test_helpers.NewTestServer(&test_helpers.TestServerOptions{
				RequestAcceptHeader: "application/json;version=0.0",
				PrivateSigningKey:   privateSigningKey,
				PublicSigningKey:    publicSigningKey,
				Resources:           []domain.IResource{testResource},
				Middlewares:         []interface{}{testMiddleware, testContextMiddleware, nil},
			})

			usersResource = users.NewResource(ctx, &users.Options{
				Database: ts.Database,
				Renderer: ts.Renderer,
			})
	"net/http/httptest"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/sogko/slumber/middlewares/context"
	"github.com/sogko/slumber/test_helpers"
)

var _ = Describe("Test Helpers", func() {

	Describe("NewTestResource", func() {

		It("should return nil routes when options.NilRoutes=true", func() {
			ctx := context.New()
			testResource := test_helpers.NewTestResource(ctx, nil, &test_helpers.TestResourceOptions{
				NilRoutes: true,
			})
			Expect(testResource.Routes()).To(BeNil())
		})
		It("should return routes when options.NilRoutes=false", func() {
			ctx := context.New()
			testResource := test_helpers.NewTestResource(ctx, nil, &test_helpers.TestResourceOptions{
				NilRoutes: false,
			})
			Expect(testResource.Routes()).ToNot(BeNil())
		})
		It("should return context", func() {
			ctx := context.New()
			testResource := test_helpers.NewTestResource(ctx, nil, &test_helpers.TestResourceOptions{
				NilRoutes: false,
			})
Example #3
0
						},
					}
					router := server.NewRouter(ctx, nil)
					router.AddRoutes(routes)
				}).Should(Panic())
			})

		})
	})
	Describe("AddResources()", func() {
		Context("Valid IResource", func() {
			It("should not panic", func() {
				Expect(func() {
					ctx := context.New()
					router := server.NewRouter(ctx, nil)
					testResources := test_helpers.NewTestResource(ctx, r, &test_helpers.TestResourceOptions{})
					router.AddResources(testResources)
				}).ShouldNot(Panic())
			})

		})
		Context("Invalid IResource", func() {
			It("should panic", func() {
				Expect(func() {
					ctx := context.New()
					router := server.NewRouter(ctx, nil)
					testResources := test_helpers.NewTestResource(ctx, r, &test_helpers.TestResourceOptions{
						NilRoutes: true,
					})
					router.AddResources(testResources)
				}).Should(Panic())