• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang raml.ParseFile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/Jumpscale/go-raml/raml.ParseFile函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseFile函数的具体用法?Golang ParseFile怎么用?Golang ParseFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ParseFile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestOauth2Middleware

func TestOauth2Middleware(t *testing.T) {
	Convey("oauth2 middleware", t, func() {

		targetdir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("middleware generation test", func() {
			apiDef := new(raml.APIDefinition)
			err := raml.ParseFile("../fixtures/security/dropbox.raml", apiDef)
			So(err, ShouldBeNil)

			err = generateSecurity(apiDef.SecuritySchemes, targetdir)
			So(err, ShouldBeNil)

			// oauth 2 in dropbox
			s, err := testLoadFile(filepath.Join(targetdir, "oauth2_Dropbox.py"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("../fixtures/security/oauth2_Dropbox.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// oauth 2 facebook
			s, err = testLoadFile(filepath.Join(targetdir, "oauth2_Facebook.py"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("../fixtures/security/oauth2_Facebook.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		})

		Convey("routes generation", func() {
			apiDef := new(raml.APIDefinition)
			err := raml.ParseFile("../fixtures/security/dropbox.raml", apiDef)
			So(err, ShouldBeNil)

			_, err = generateServerResources(apiDef, targetdir)
			So(err, ShouldBeNil)

			// check route
			s, err := testLoadFile(filepath.Join(targetdir, "deliveries.py"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("../fixtures/security/deliveries.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		})

		Reset(func() {
			os.RemoveAll(targetdir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:56,代码来源:security_test.go


示例2: TestGenerateClientFromRaml

func TestGenerateClientFromRaml(t *testing.T) {
	Convey("generate client from raml", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("./fixtures/client_resources/client.raml", apiDef)
		So(err, ShouldBeNil)

		targetdir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("Simple client from raml", func() {
			err = GenerateClient(apiDef, targetdir, "theclient", "go", "client")
			So(err, ShouldBeNil)

			s, err := testLoadFile(filepath.Join(targetdir, "client_structapitest.go"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("./fixtures/client_resources/client_structapitest.txt")
			So(err, ShouldBeNil)

			So(tmpl, ShouldEqual, s)
		})

		Reset(func() {
			os.RemoveAll(targetdir)
		})
	})
}
开发者ID:robvanmieghem,项目名称:go-raml,代码行数:27,代码来源:client_test.go


示例3: TestPythonResource

func TestPythonResource(t *testing.T) {
	Convey("resource generator", t, func() {
		targetdir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("resource with request body", func() {
			apiDef := new(raml.APIDefinition)
			err := raml.ParseFile("../fixtures/server_resources/deliveries.raml", apiDef)
			So(err, ShouldBeNil)

			_, err = generateServerResources(apiDef, targetdir)
			So(err, ShouldBeNil)

			// check  api implementation
			s, err := testLoadFile(filepath.Join(targetdir, "deliveries.py"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("../fixtures/server_resources/deliveries.py")
			So(err, ShouldBeNil)
			So(s, ShouldEqual, tmpl)
		})

		Reset(func() {
			os.RemoveAll(targetdir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:27,代码来源:resources_test.go


示例4: TestGenerateClassFromBody

func TestGenerateClassFromBody(t *testing.T) {
	Convey("generate struct body from raml", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("../fixtures/struct/struct.raml", apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("python class from request/response bodies", func() {
			rs := getAllResources(apiDef, true)
			err = generateClassesFromBodies(rs, targetDir)
			So(err, ShouldBeNil)

			// req body
			s, err := testLoadFile(filepath.Join(targetDir, "UsersPostReqBody.py"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("../fixtures/struct/UsersPostReqBody.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:30,代码来源:body_test.go


示例5: TestGenerateClientFromRaml

func TestGenerateClientFromRaml(t *testing.T) {
	Convey("generate client from raml", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("./fixtures/client_resources/client.raml", apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		err = GenerateClient(apiDef, targetDir, "theclient", "go", "client")
		So(err, ShouldBeNil)
		rootFixture := "./fixtures/client_resources"
		checks := []struct {
			Result   string
			Expected string
		}{
			{"client_structapitest.go", "client_structapitest.txt"},
			{"users_service.go", "users_service.txt"},
		}

		for _, check := range checks {
			s, err := testLoadFile(filepath.Join(targetDir, check.Result))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		}

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:35,代码来源:client_test.go


示例6: Execute

//Execute generates a client from a RAML specification
func (command *ClientCommand) Execute() error {
	log.Debug("Generating a rest client for ", command.Language)
	apiDef := new(raml.APIDefinition)
	err := raml.ParseFile(command.RamlFile, apiDef)
	if err != nil {
		return err
	}
	return codegen.GenerateClient(apiDef, command.Dir, command.PackageName, command.Language, command.ImportPath)
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:10,代码来源:client.go


示例7: TestGenerateStructBodyFromRaml

func TestGenerateStructBodyFromRaml(t *testing.T) {
	Convey("generate struct body from raml", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("./fixtures/struct/struct.raml", apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("simple body", func() {
			err := generateBodyStructs(apiDef, targetDir, "main", langGo)
			So(err, ShouldBeNil)

			//load and compare UsersIdGetRespBody
			s, err := testLoadFile(filepath.Join(targetDir, "UsersIdGetRespBody.go"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("./fixtures/struct/UsersIdGetRespBody.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			//load and compare usersgetreqbody
			s, err = testLoadFile(filepath.Join(targetDir, "UsersPostReqBody.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("./fixtures/struct/UsersPostReqBody.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		})

		Convey("python class from request/response bodies", func() {
			err = generateBodyStructs(apiDef, targetDir, "", langPython)
			So(err, ShouldBeNil)

			// req body
			s, err := testLoadFile(filepath.Join(targetDir, "UsersPostReqBody.py"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("./fixtures/struct/UsersPostReqBody.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:robvanmieghem,项目名称:go-raml,代码行数:52,代码来源:body_test.go


示例8: TestGeneratePythonClass

func TestGeneratePythonClass(t *testing.T) {
	Convey("generate python class from raml", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("./fixtures/struct/struct.raml", apiDef)
		So(err, ShouldBeNil)
		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("python class from raml Types", func() {
			err = generatePythonClasses(apiDef.Types, targetDir)
			So(err, ShouldBeNil)

			// strings validator
			s, err := testLoadFile(filepath.Join(targetDir, "ValidationString.py"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("./fixtures/struct/ValidationString.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// with form field
			s, err = testLoadFile(filepath.Join(targetDir, "Cage.py"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("./fixtures/struct/Cage.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// FieldList of FormField
			s, err = testLoadFile(filepath.Join(targetDir, "animal.py"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("./fixtures/struct/animal.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// another test could be seen at body_test.go
		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})

	})
}
开发者ID:robvanmieghem,项目名称:go-raml,代码行数:48,代码来源:class_python_test.go


示例9: Execute

//Execute generates a client from a RAML specification
func (command *CapnpCommand) Execute() error {
	var apiDef raml.APIDefinition

	command.Language = strings.ToLower(command.Language)
	if command.Language != "go" && command.Language != "plain" {
		return fmt.Errorf("canpnp generator only support plain & Go-compatible schema")
	}

	log.Debug("Generating capnp models")

	err := raml.ParseFile(command.RAMLFile, &apiDef)
	if err != nil {
		return err
	}
	return codegen.GenerateCapnp(&apiDef, command.Dir, command.Language, command.Package)
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:17,代码来源:capnp.go


示例10: TestGenerateObjectFromRaml

func TestGenerateObjectFromRaml(t *testing.T) {
	Convey("generate object from raml", t, func() {
		var apiDef raml.APIDefinition
		err := raml.ParseFile("../fixtures/struct/struct.raml", &apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("Simple struct from raml", func() {
			err = generateObjects(apiDef.Types, targetDir)
			So(err, ShouldBeNil)

			rootFixture := "./fixtures/object/"
			checks := []struct {
				Result   string
				Expected string
			}{
				{"EnumCity.nim", "EnumCity.nim"},
				{"animal.nim", "animal.nim"},
				{"Cage.nim", "Cage.nim"},
				{"Cat.nim", "Cat.nim"},
				{"ArrayOfCats.nim", "ArrayOfCats.nim"},
				{"BidimensionalArrayOfCats.nim", "BidimensionalArrayOfCats.nim"},
			}

			for _, check := range checks {
				s, err := testLoadFile(filepath.Join(targetDir, check.Result))
				So(err, ShouldBeNil)

				tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
				So(err, ShouldBeNil)

				So(s, ShouldEqual, tmpl)
			}

		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:43,代码来源:object_test.go


示例11: TestGeneratePythonClientFromRaml

func TestGeneratePythonClientFromRaml(t *testing.T) {
	Convey("generate python client", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("./fixtures/client/client.raml", apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("Simple client", func() {
			client := NewClient(apiDef)
			err = client.Generate(targetDir)
			So(err, ShouldBeNil)

			rootFixture := "./fixtures/client"
			// cek with generated with fixtures
			checks := []struct {
				Result   string
				Expected string
			}{
				{"client.py", "client.py"},
				{"__init__.py", "__init__.py"},
				{"client_utils.py", "client_utils.py"},
				{"users_service.py", "users_service.py"},
			}

			for _, check := range checks {
				s, err := testLoadFile(filepath.Join(targetDir, check.Result))
				So(err, ShouldBeNil)

				tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
				So(err, ShouldBeNil)

				So(s, ShouldEqual, tmpl)
			}
		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:42,代码来源:client_test.go


示例12: TestGenerateServer

func TestGenerateServer(t *testing.T) {
	Convey("generate server from raml", t, func() {
		var apiDef raml.APIDefinition
		err := raml.ParseFile("../fixtures/server_resources/deliveries.raml", &apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		ns := Server{
			Title:      apiDef.Title,
			APIDef:     &apiDef,
			APIDocsDir: "apidocs",
			Dir:        targetDir,
		}
		err = ns.Generate()
		So(err, ShouldBeNil)

		rootFixture := "./fixtures/server/delivery"
		checks := []struct {
			Result   string
			Expected string
		}{
			{"main.nim", "main.nim"},
			{"deliveries_api.nim", "deliveries_api.nim"},
		}

		for _, check := range checks {
			s, err := testLoadFile(filepath.Join(targetDir, check.Result))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		}

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:42,代码来源:server_test.go


示例13: TestGenerateClient

func TestGenerateClient(t *testing.T) {
	Convey("generate client from raml", t, func() {
		var apiDef raml.APIDefinition
		err := raml.ParseFile("../fixtures/client_resources/client.raml", &apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		client := Client{
			APIDef: &apiDef,
			Dir:    targetDir,
		}
		err = client.Generate()
		So(err, ShouldBeNil)

		rootFixture := "./fixtures/resource/client"
		checks := []struct {
			Result   string
			Expected string
		}{
			{"client.nim", "client.nim"},
			{"Users_service.nim", "Users_service.nim"},
		}

		for _, check := range checks {
			s, err := testLoadFile(filepath.Join(targetDir, check.Result))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		}

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:40,代码来源:client_test.go


示例14: TestGenerateResourceAPI

func TestGenerateResourceAPI(t *testing.T) {
	Convey("generate object from raml", t, func() {
		var apiDef raml.APIDefinition
		err := raml.ParseFile("../fixtures/server_resources/deliveries.raml", &apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("deliveries API", func() {
			err = generateResourceAPIs(getAllResources(&apiDef, true), targetDir)
			So(err, ShouldBeNil)

			rootFixture := "./fixtures/resource/"
			checks := []struct {
				Result   string
				Expected string
			}{
				{"deliveries_api.nim", "deliveries_api.nim"},
			}

			for _, check := range checks {
				s, err := testLoadFile(filepath.Join(targetDir, check.Result))
				So(err, ShouldBeNil)

				tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
				So(err, ShouldBeNil)

				So(s, ShouldEqual, tmpl)
			}

		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:38,代码来源:resource_test.go


示例15: TestGoLibrary

func TestGoLibrary(t *testing.T) {
	Convey("Library usage in server", t, func() {
		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		err = GenerateServer("./fixtures/libraries/api.raml", targetDir, "main", "go", "apidocs", "examples.com/ramlcode", true)
		So(err, ShouldBeNil)

		rootFixture := "./fixtures/libraries/go_server"
		checks := []struct {
			Result   string
			Expected string
		}{
			{"Place.go", "Place.txt"},
			{"dirs_api.go", "dirs_api.txt"},
			{"configs_api.go", "configs_api.txt"},
		}

		for _, check := range checks {
			s, err := testLoadFile(filepath.Join(targetDir, check.Result))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		}

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
	Convey("Library usage in client", t, func() {
		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		apiDef := new(raml.APIDefinition)
		err = raml.ParseFile("./fixtures/libraries/api.raml", apiDef)
		So(err, ShouldBeNil)

		err = GenerateClient(apiDef, targetDir, "theclient", langGo, "examples.com/client")
		So(err, ShouldBeNil)

		rootFixture := "./fixtures/libraries/go_client"
		checks := []struct {
			Result   string
			Expected string
		}{
			{"Place.go", "Place.txt"},
			{"client_exampleapi.go", "client_exampleapi.txt"},
			{"client_utils.go", "client_utils.txt"},
		}

		for _, check := range checks {
			s, err := testLoadFile(filepath.Join(targetDir, check.Result))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		}

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})

}
开发者ID:robvanmieghem,项目名称:go-raml,代码行数:69,代码来源:libraries_go_test.go


示例16: TestGenerateCapnpSchema

func TestGenerateCapnpSchema(t *testing.T) {
	Convey("generate capnp schema from raml", t, func() {
		var apiDef raml.APIDefinition
		err := raml.ParseFile("./fixtures/struct.raml", &apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("Schema for Python & Nim", func() {
			err = GenerateCapnp(&apiDef, targetDir, "nim", "")
			So(err, ShouldBeNil)

			rootFixture := "./fixtures/struct/vanilla"
			checks := []struct {
				Result   string
				Expected string
			}{
				{"Animal.capnp", "Animal.capnp"},
				{"Cage.capnp", "Cage.capnp"},
				{"Admin.capnp", "Admin.capnp"},
				{"EnumAdminClearanceLevel.capnp", "EnumAdminClearanceLevel.capnp"},
			}

			for _, check := range checks {
				s, err := testLoadFile(filepath.Join(targetDir, check.Result))
				So(err, ShouldBeNil)

				tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
				So(err, ShouldBeNil)

				So(s, ShouldEqual, tmpl)
			}

		})

		Convey("Schema for Go", func() {
			err = GenerateCapnp(&apiDef, targetDir, "go", "main")
			So(err, ShouldBeNil)

			rootFixture := "./fixtures/struct/golang"
			checks := []struct {
				Result   string
				Expected string
			}{
				{"Animal.capnp", "Animal.capnp"},
				{"Cage.capnp", "Cage.capnp"},
				{"Admin.capnp", "Admin.capnp"},
				{"EnumAdminClearanceLevel.capnp", "EnumAdminClearanceLevel.capnp"},
			}

			for _, check := range checks {
				s, err := testLoadFile(filepath.Join(targetDir, check.Result))
				So(err, ShouldBeNil)

				tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
				So(err, ShouldBeNil)

				So(s, ShouldEqual, tmpl)
			}

		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:68,代码来源:struct_test.go


示例17: TestGoLibrary

func TestGoLibrary(t *testing.T) {
	Convey("Library usage in server", t, func() {
		var apiDef raml.APIDefinition

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		err = raml.ParseFile("../fixtures/libraries/api.raml", &apiDef)
		So(err, ShouldBeNil)

		server := NewServer(&apiDef, "main", "apidocs", "examples.com/ramlcode", true)
		err = server.Generate(targetDir)
		So(err, ShouldBeNil)

		rootFixture := "../fixtures/libraries/go_server"
		checks := []struct {
			Result   string
			Expected string
		}{
			{"Place.go", "Place.txt"},
			{"dirs_api.go", "dirs_api.txt"},
			{"configs_api.go", "configs_api.txt"},
		}

		for _, check := range checks {
			s, err := testLoadFile(filepath.Join(targetDir, check.Result))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		}

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})

	Convey("Library usage in client", t, func() {
		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		apiDef := new(raml.APIDefinition)
		err = raml.ParseFile("../fixtures/libraries/api.raml", apiDef)
		So(err, ShouldBeNil)

		client, err := NewClient(apiDef, "theclient", "examples.com/theclient")
		So(err, ShouldBeNil)

		err = client.Generate(targetDir)
		So(err, ShouldBeNil)

		rootFixture := "../fixtures/libraries/go_client"
		checks := []struct {
			Result   string
			Expected string
		}{
			{"Place.go", "Place.txt"},
			{"client_exampleapi.go", "client_exampleapi.txt"},
			{"client_utils.go", "client_utils.txt"},
			{"dirs_service.go", "dirs_service.txt"},
			{"configs_service.go", "configs_service.txt"},
		}

		for _, check := range checks {
			s, err := testLoadFile(filepath.Join(targetDir, check.Result))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		}

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})

	Convey("raml-examples", t, func() {
		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("server", func() {
			var apiDef raml.APIDefinition

			err = raml.ParseFile("../fixtures/raml-examples/libraries/api.raml", &apiDef)
			So(err, ShouldBeNil)

			server := NewServer(&apiDef, "main", "apidocs", "examples.com/libro", true)
			err = server.Generate(targetDir)
			So(err, ShouldBeNil)

			rootFixture := "../fixtures/libraries/raml-examples/go_server"
			checks := []struct {
				Result   string
				Expected string
			}{
				{"person_api.go", "person_api.txt"},
//.........这里部分代码省略.........
开发者ID:Jumpscale,项目名称:go-raml,代码行数:101,代码来源:libraries_test.go


示例18: TestResource

func TestResource(t *testing.T) {
	Convey("resource generator", t, func() {
		targetdir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		apiDef := new(raml.APIDefinition)

		Convey("simple resource", func() {
			err := raml.ParseFile("./fixtures/server_resources/deliveries.raml", apiDef)
			So(err, ShouldBeNil)

			_, err = generateServerResources(apiDef, targetdir, "main", "go")
			So(err, ShouldBeNil)

			// check interface file
			s, err := testLoadFile(filepath.Join(targetdir, "deliveries_if.go"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("./fixtures/server_resources/deliveries_if.txt")
			So(err, ShouldBeNil)
			So(s, ShouldEqual, tmpl)

			// check api implemetation file
			s, err = testLoadFile(filepath.Join(targetdir, "deliveries_api.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("./fixtures/server_resources/deliveries_api.txt")
			So(err, ShouldBeNil)
			So(s, ShouldEqual, tmpl)
		})

		Convey("resource with request body", func() {
			err := raml.ParseFile("./fixtures/server_resources/usergroups.raml", apiDef)
			So(err, ShouldBeNil)

			_, err = generateServerResources(apiDef, targetdir, "main", "go")
			So(err, ShouldBeNil)

			// check users api implementation
			s, err := testLoadFile(filepath.Join(targetdir, "users_api.go"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("./fixtures/server_resources/users_api.txt")
			So(err, ShouldBeNil)
			So(s, ShouldEqual, tmpl)

			// check user interface
			s, err = testLoadFile(filepath.Join(targetdir, "users_if.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("./fixtures/server_resources/users_if.txt")
			So(err, ShouldBeNil)
			So(s, ShouldEqual, tmpl)

		})

		Reset(func() {
			os.RemoveAll(targetdir)
		})
	})
}
开发者ID:robvanmieghem,项目名称:go-raml,代码行数:61,代码来源:server_resources_test.go


示例19: TestGenerateStructFromRaml

func TestGenerateStructFromRaml(t *testing.T) {
	Convey("generate struct from raml", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("../fixtures/struct/struct.raml", apiDef)
		So(err, ShouldBeNil)
		targetdir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("Simple struct from raml", func() {
			err = generateStructs(apiDef.Types, targetdir, "main")
			So(err, ShouldBeNil)

			//first test
			s, err := testLoadFile(filepath.Join(targetdir, "EnumCity.go"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("../fixtures/struct/enumcity.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			//second test
			s, err = testLoadFile(filepath.Join(targetdir, "animal.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("../fixtures/struct/animal.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			//third test, single inheritance
			s, err = testLoadFile(filepath.Join(targetdir, "SingleInheritance.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("../fixtures/struct/singleinheritance.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			//fourth test, multiple inheritance
			s, err = testLoadFile(filepath.Join(targetdir, "MultipleInheritance.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("../fixtures/struct/multipleinheritance.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			//fifth test, array of object
			s, err = testLoadFile(filepath.Join(targetdir, "ArrayOfCats.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("../fixtures/struct/arrayofcats.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// bidimensional array
			s, err = testLoadFile(filepath.Join(targetdir, "BidimensionalArrayOfCats.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("../fixtures/struct/bidimensionalarrayofcats.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// using map type & testing case sensitive type name
			s, err = testLoadFile(filepath.Join(targetdir, "petshop.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("../fixtures/struct/petshop.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// Union
			s, err = testLoadFile(filepath.Join(targetdir, "Pet.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("../fixtures/struct/Pet.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// Array of union
			s, err = testLoadFile(filepath.Join(targetdir, "ArrayOfPets.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("../fixtures/struct/ArrayOfPets.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// Specialization
			s, err = testLoadFile(filepath.Join(targetdir, "Specialization.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("../fixtures/struct/Specialization.txt")
			So(err, ShouldBeNil)

//.........这里部分代码省略.........
开发者ID:Jumpscale,项目名称:go-raml,代码行数:101,代码来源:struct_test.go


示例20: TestGenerateObjectMethodBody

func TestGenerateObjectMethodBody(t *testing.T) {
	Convey("generate object from method body", t, func() {
		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("generate request body", func() {
			var body raml.Bodies
			properties := map[string]interface{}{
				"age": map[interface{}]interface{}{
					"type": "integer",
				},
				"ID": map[interface{}]interface{}{
					"type": "string",
				},
				"item": map[interface{}]interface{}{},
				"grades": map[interface{}]interface{}{
					"type": "integer[]",
				},
			}
			body.ApplicationJSON = &raml.BodiesProperty{
				Properties: properties,
			}

			_, err := generateObjectFromBody("usersPost", &body, true, targetDir)
			So(err, ShouldBeNil)

			s, err := testLoadFile(filepath.Join(targetDir, "usersPostReqBody.nim"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("./fixtures/object/usersPostReqBody.nim")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

		})

		Convey("Simple object from raml", func() {
			var apiDef raml.APIDefinition
			err := raml.ParseFile("../fixtures/struct/struct.raml", &apiDef)
			So(err, ShouldBeNil)

			_, err = generateObjectsFromBodies(getAllResources(&apiDef, true), targetDir)
			So(err, ShouldBeNil)

			rootFixture := "./fixtures/object/"
			checks := []struct {
				Result   string
				Expected string
			}{
				{"usersPostReqBody.nim", "usersPostReqBody.nim"},
				{"usersByIdGetRespBody.nim", "usersByIdGetRespBody.nim"},
			}

			for _, check := range checks {
				s, err := testLoadFile(filepath.Join(targetDir, check.Result))
				So(err, ShouldBeNil)

				tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
				So(err, ShouldBeNil)

				So(s, ShouldEqual, tmpl)
			}

		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:70,代码来源:object_test.go



注:本文中的github.com/Jumpscale/go-raml/raml.ParseFile函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang curses.CPrint函数代码示例发布时间:2022-05-23
下一篇:
Golang httprouter.Router类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap