Ejemplo n.º 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)
}
Ejemplo n.º 2
0
	})

	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": `tasks:
                             - vars:
                                 person: John
                     `,
					"path": ".*",
				})
				Expect(err).ToNot(HaveOccurred())
				extensions := []*schema.Extension{extension}
				env := gohanscript.NewEnvironment(timelimit)
				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())
			})
		})
		Context("When extension URL uses file:// protocol", func() {
			It("should read the file and run the extension", func() {
				extension, err := schema.NewExtension(map[string]interface{}{
					"id":   "test_extension",
					"url":  "file://./examples/variable.yaml",
					"path": ".*",