Пример #1
0
func (server *Server) newEnvironment(name string) extension.Environment {
	envs := []extension.Environment{}
	timelimit := time.Duration(server.timelimit) * time.Second
	for _, extension := range server.extensions {
		switch extension {
		case "javascript":
			envs = append(envs, otto.NewEnvironment(name, server.db, server.keystoneIdentity, timelimit))
		case "gohanscript":
			envs = append(envs, gohanscript.NewEnvironment(timelimit))
		case "go":
			envs = append(envs, golang.NewEnvironment())
		}
	}
	return extension.NewEnvironment(envs)
}
Пример #2
0
var _ = Describe("Gohanscript extension manager", func() {
	AfterEach(func() {
		extension.ClearManager()
	})

	Describe("Loading an extension", func() {
		Context("When extension uses code property", func() {
			It("should run the extension code", func() {
				extension, err := schema.NewExtension(map[string]interface{}{
					"id":        "test_extension",
					"code":      "test_callback",
					"code_type": "go",
					"path":      ".*",
				})
				Expect(err).ToNot(HaveOccurred())
				extensions := []*schema.Extension{extension}
				env := golang.NewEnvironment()
				Expect(env.LoadExtensionsForPath(extensions, "test_path")).To(Succeed())

				context := map[string]interface{}{
					"id": "test",
				}
				Expect(env.HandleEvent("test_event", context)).To(Succeed())
				Expect(context["person"]).ToNot(BeNil())
			})
		})
	})

})