예제 #1
0
func BenchmarkProcessBookingSource(b *testing.B) {
	revel.Init("", "git.masontest.com/branches/goserver/workers/revel/samples/booking", "")
	revel.TRACE = log.New(ioutil.Discard, "", 0)
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		_, err := ProcessSource(revel.CodePaths)
		if err != nil {
			b.Error("Unexpected error:", err)
		}
	}
}
예제 #2
0
파일: build.go 프로젝트: nangong92t/go_src
// Build the app:
// 1. Generate the the main.go file.
// 2. Run the appropriate "go build" command.
// Requires that revel.Init has been called previously.
// Returns the path to the built binary, and an error if there was a problem building it.
func Build(appEnv, appName, appPath string, logger *plugins.ServerLog) {
	revel.Init(appEnv, appPath, "")

	// First, clear the generated files (to avoid them messing with ProcessSource).
	cleanSource(appName)

	sourceInfo, compileError := ProcessSource(revel.CodePaths)
	if compileError != nil {
		panic(compileError)
	}

	checkIsHaveArgs := func(ctrl []*TypeInfo) bool {
		result := false

	L:
		for _, c := range ctrl {
			for _, a := range c.MethodSpecs {
				if len(a.Args) > 0 {
					result = true
					break L
				}
			}
		}

		return result
	}

	ctrlSpecs := sourceInfo.ControllerSpecs()

	// Generate two source files.
	templateArgs := map[string]interface{}{
		"AppName":        appName,
		"AppPath":        appPath,
		"AppEnv":         appEnv,
		"Controllers":    ctrlSpecs,
		"ValidationKeys": sourceInfo.ValidationKeys,
		"ImportPaths":    calcImportAliases(sourceInfo),
		"TestSuites":     sourceInfo.TestSuites(),
		"IsArgInCtrl":    checkIsHaveArgs(ctrlSpecs),
	}

	genSource(runtimePath, appName+".go", MAIN, templateArgs)
	// genSource("routes", "routes.go", ROUTES, templateArgs)

}
예제 #3
0
func TestProcessBookingSource(t *testing.T) {
	revel.Init("prod", "git.masontest.com/branches/goserver/workers/revel/samples/booking", "")
	sourceInfo, err := ProcessSource([]string{revel.AppPath})
	if err != nil {
		t.Fatal("Failed to process booking source with error:", err)
	}

	CONTROLLER_PKG := "git.masontest.com/branches/goserver/workers/revel/samples/booking/app/controllers"
	expectedControllerSpecs := []*TypeInfo{
		{"GorpController", CONTROLLER_PKG, "controllers", nil, nil},
		{"Application", CONTROLLER_PKG, "controllers", nil, nil},
		{"Hotels", CONTROLLER_PKG, "controllers", nil, nil},
	}
	if len(sourceInfo.ControllerSpecs()) != len(expectedControllerSpecs) {
		t.Errorf("Unexpected number of controllers found.  Expected %d, Found %d",
			len(expectedControllerSpecs), len(sourceInfo.ControllerSpecs()))
	}

NEXT_TEST:
	for _, expected := range expectedControllerSpecs {
		for _, actual := range sourceInfo.ControllerSpecs() {
			if actual.StructName == expected.StructName {
				if actual.ImportPath != expected.ImportPath {
					t.Errorf("%s expected to have import path %s, actual %s",
						actual.StructName, expected.ImportPath, actual.ImportPath)
				}
				if actual.PackageName != expected.PackageName {
					t.Errorf("%s expected to have package name %s, actual %s",
						actual.StructName, expected.PackageName, actual.PackageName)
				}
				continue NEXT_TEST
			}
		}
		t.Errorf("Expected to find controller %s, but did not.  Actuals: %s",
			expected.StructName, sourceInfo.ControllerSpecs())
	}
}