Exemplo n.º 1
0
func TestDoesNotOverwriteInterface() {
	i := 100
	a := &TypeAnswerStruct{}
	var v struct {
		K *int              `inject:""`
		A Answerable        `inject:""`
		B *TypeNestedStruct `inject:""`
	}
	fmt.Println(v)
	v.A = a
	v.K = &i
	/*
		var g inject.Graph
		if err := g.Provide(&inject.Object{Name: "inttest", Value: &i}); err != nil {
			fmt.Println(err)
		}
	*/
	if err := inject.Populate(&v); err != nil {
		fmt.Println(err)
	}
	a.answer = 1
	i = 99
	fmt.Println(v.A)
	fmt.Println(v.B)
	fmt.Println(*v.K)
	if v.A != a {
		fmt.Println("original A was lost")
	}
	if v.B == nil {
		fmt.Println("v.B is nil")
	}
}
Exemplo n.º 2
0
func init() {
	// Filters is the default set of global filters.
	revel.Filters = []revel.Filter{
		CorsFilter,
		revel.PanicFilter,             // Recover from panics and display an error page instead.
		revel.RouterFilter,            // Use the routing table to select the right Action
		revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters.
		revel.ParamsFilter,            // Parse parameters into Controller.Params.
		//		revel.SessionFilter,           // Restore and write the session cookie.
		//		revel.FlashFilter,             // Restore and write the flash cookie.
		revel.ValidationFilter,  // Restore kept validation errors and save new ones from cookie.
		revel.I18nFilter,        // Resolve the requested language
		HeaderFilter,            // Add some security based headers
		revel.InterceptorFilter, // Run interceptors around the action.
		revel.CompressFilter,    // Compress the result.
		revel.ActionInvoker,     // Invoke the action.
	}

	persistence.InitDb()

	var app controllers.AccountController

	if err := inject.Populate(&app); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
Exemplo n.º 3
0
func TestInjectWithStructValue() {
	var v TypeWithStructValue
	if err := inject.Populate(&v); err != nil {
		fmt.Println(err)
	}
	fmt.Println(v)
}
Exemplo n.º 4
0
func TestInterfaceIncludingPrivate(t *testing.T) {
	var v struct {
		A Answerable        `inject:""`
		B *TypeNestedStruct `inject:"private"`
		C *TypeAnswerStruct `inject:""`
	}
	if err := inject.Populate(&v); err != nil {
		t.Fatal(err)
	}
	if v.A == nil {
		t.Fatal("v.A is nil")
	}
	if v.B == nil {
		t.Fatal("v.B is nil")
	}
	if v.C == nil {
		t.Fatal("v.C is nil")
	}
	if v.A != v.C {
		t.Fatal("v.A != v.C")
	}
	if v.A == v.B {
		t.Fatal("v.A == v.B")
	}
}
Exemplo n.º 5
0
func TestInterfaceIncludingPrivate() {
	var v struct {
		A Answerable        `inject:""`
		B *TypeNestedStruct `inject:"private"`
		C *TypeAnswerStruct `inject:""`
	}
	if err := inject.Populate(&v); err != nil {
		fmt.Println(err)
	}
	fmt.Println(v)

	if v.A == nil {
		fmt.Println("v.A is nil")
	}
	if v.B == nil {
		fmt.Println("v.B is nil")
	}
	if v.C == nil {
		fmt.Println("v.C is nil")
	}
	if v.A != v.C {
		fmt.Println("v.A != v.C")
	}
	if v.A == v.B {
		fmt.Println("v.A == v.B")
	}
}
Exemplo n.º 6
0
func TestInjectWithStructValue(t *testing.T) {
	var v TypeWithStructValue
	if err := inject.Populate(&v); err != nil {
		t.Fatal(err)
	}
	if v.Inline.A == nil {
		t.Fatal("v.Inline.A is nil")
	}
}
Exemplo n.º 7
0
func TagWithJustColon() {
	var a TypeWithJustColon
	err := inject.Populate(&a)
	if err == nil {
		fmt.Println(a)
	} else {
		fmt.Println(err)
	}
}
Exemplo n.º 8
0
func initApp() HomomorphicEncryptionBackendApp {

	var app HomomorphicEncryptionBackendApp

	inject.Populate(&app)

	app.Router.init()

	return app
}
Exemplo n.º 9
0
func TestInjectMap(t *testing.T) {
	var v struct {
		A map[string]int `inject:"private"`
	}
	if err := inject.Populate(&v); err != nil {
		t.Fatal(err)
	}
	if v.A == nil {
		t.Fatal("v.A is nil")
	}
}
Exemplo n.º 10
0
func TestErrorOnNonPointerStructInject(t *testing.T) {
	var a TypeWithNonPointerStructInject
	err := inject.Populate(&a)
	if err == nil {
		t.Fatalf("expected error for %+v", a)
	}

	const msg = "found inject tag on unsupported field A in type *inject_test.TypeWithNonPointerStructInject"
	if err.Error() != msg {
		t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
	}
}
Exemplo n.º 11
0
func TestProvideTwoOfTheSameWithPopulate(t *testing.T) {
	a := TypeAnswerStruct{}
	err := inject.Populate(&a, &a)
	if err == nil {
		t.Fatal("expected error")
	}

	const msg = "provided two unnamed instances of type *github.com/facebookgo/inject_test.TypeAnswerStruct"
	if err.Error() != msg {
		t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
	}
}
Exemplo n.º 12
0
func TestPrivateIsFollowed(t *testing.T) {
	var v struct {
		A *TypeNestedStruct `inject:"private"`
	}

	if err := inject.Populate(&v); err != nil {
		t.Fatal(err)
	}
	if v.A.A == nil {
		t.Fatal("v.A.A is nil")
	}
}
Exemplo n.º 13
0
func TestInjectInterfaceMissing(t *testing.T) {
	var v TypeInjectInterfaceMissing
	err := inject.Populate(&v)
	if err == nil {
		t.Fatal("did not find expected error")
	}

	const msg = "found no assignable value for field Answerable in type *inject_test.TypeInjectInterfaceMissing"
	if err.Error() != msg {
		t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
	}
}
Exemplo n.º 14
0
func TestInjectTwoSatisfyInterface(t *testing.T) {
	var v TypeInjectTwoSatisfyInterface
	err := inject.Populate(&v)
	if err == nil {
		t.Fatal("did not find expected error")
	}

	const msg = "found two assignable values for field Answerable in type *inject_test.TypeInjectTwoSatisfyInterface. one type *inject_test.TypeAnswerStruct with value &{0 0} and another type *inject_test.TypeNestedStruct with value <*inject_test.TypeNestedStruct Value>"
	if err.Error() != msg {
		t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
	}
}
Exemplo n.º 15
0
func TestInjectPrivateInterface(t *testing.T) {
	var v TypeInjectPrivateInterface
	err := inject.Populate(&v)
	if err == nil {
		t.Fatal("did not find expected error")
	}

	const msg = "found private inject tag on interface field Answerable in type *inject_test.TypeInjectPrivateInterface"
	if err.Error() != msg {
		t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
	}
}
Exemplo n.º 16
0
func TestInjectOnPrivateInterfaceField(t *testing.T) {
	var a TypeWithInjectOnPrivateField
	err := inject.Populate(&a)
	if err == nil {
		t.Fatal("did not find expected error")
	}

	const msg = "inject requested on unexported field a in type *inject_test.TypeWithInjectOnPrivateField"
	if err.Error() != msg {
		t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
	}
}
Exemplo n.º 17
0
func TestInjectMapWithoutPrivate(t *testing.T) {
	var v TypeInjectWithMapWithoutPrivate
	err := inject.Populate(&v)
	if err == nil {
		t.Fatalf("expected error for %+v", v)
	}

	const msg = "inject on map field A in type *inject_test.TypeInjectWithMapWithoutPrivate must be named or private"
	if err.Error() != msg {
		t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
	}
}
Exemplo n.º 18
0
func TestInjectInlinePrivate(t *testing.T) {
	var v TypeWithInlineStructWithPrivate
	err := inject.Populate(&v)
	if err == nil {
		t.Fatal("was expecting an error")
	}

	const msg = "cannot use private inject on inline struct on field Inline in type *inject_test.TypeWithInlineStructWithPrivate"
	if err.Error() != msg {
		t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
	}
}
Exemplo n.º 19
0
func TestTagWithMissingNamed(t *testing.T) {
	var a TypeWithMissingNamed
	err := inject.Populate(&a)
	if err == nil {
		t.Fatalf("expected error for %+v", a)
	}

	const msg = "did not find object named foo required by field A in type *inject_test.TypeWithMissingNamed"
	if err.Error() != msg {
		t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
	}
}
Exemplo n.º 20
0
func TestTagWithOpenQuote(t *testing.T) {
	var a TypeWithOpenQuote
	err := inject.Populate(&a)
	if err == nil {
		t.Fatalf("expected error for %+v", a)
	}

	const msg = "unexpected tag format `inject:\"` for field A in type *inject_test.TypeWithOpenQuote"
	if err.Error() != msg {
		t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
	}
}
Exemplo n.º 21
0
func ErrorOnNonPointerInject() {
	var a TypeWithNonPointerInject
	err := inject.Populate(&a)
	if err == nil {
		fmt.Println(a)
	} else {
		fmt.Println(err.Error())
		const msg = "found inject tag on unsupported field A in type *main.TypeWithNonPointerInject"
		if err.Error() != msg {
			fmt.Errorf("expected:\n%s\nactual:\n%s", msg, err.Error())
		}
	}
}
Exemplo n.º 22
0
func TestInjectInterface() {
	var v TypeInjectInterface
	if err := inject.Populate(&v); err != nil {
		fmt.Println(err)
	}
	fmt.Println(v.Answerable)
	fmt.Println(v.A)
	if v.Answerable == nil || v.Answerable != v.A {
		fmt.Println(
			v.Answerable,
			v.A,
		)
	}
}
Exemplo n.º 23
0
func main() {
	application := new(libraryApplication)

	if error := inject.Populate(
		application,
		new(bookservice.BookService),
		new(borrowservice.BorrowService),
		new(loggerservice.LoggerService),
		new(userservice.UserService),
	); nil != error {
		log.Fatalf("Error occured while populating graph: %v", error)
	}

	application.run()
}
Exemplo n.º 24
0
func TestInjectInterface(t *testing.T) {
	var v TypeInjectInterface
	if err := inject.Populate(&v); err != nil {
		t.Fatal(err)
	}
	if v.Answerable == nil || v.Answerable != v.A {
		t.Fatalf(
			"expected the same but got Answerable = %T %+v / A = %T %+v",
			v.Answerable,
			v.Answerable,
			v.A,
			v.A,
		)
	}
}
Exemplo n.º 25
0
func TestInjectInvalidInline(t *testing.T) {
	var v struct {
		A *TypeAnswerStruct `inject:"inline"`
	}

	err := inject.Populate(&v)
	if err == nil {
		t.Fatal("was expecting an error")
	}

	const msg = `inline requested on non inlined field A in type *struct { A *inject_test.TypeAnswerStruct "inject:\"inline\"" }`
	if err.Error() != msg {
		t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
	}
}
Exemplo n.º 26
0
func TestRequireTag(t *testing.T) {
	var v struct {
		A *TypeAnswerStruct
		B *TypeNestedStruct `inject:""`
	}

	if err := inject.Populate(&v); err != nil {
		t.Fatal(err)
	}
	if v.A != nil {
		t.Fatal("v.A is not nil")
	}
	if v.B == nil {
		t.Fatal("v.B is nil")
	}
}
Exemplo n.º 27
0
func Private() {
	var v struct {
		A *TypeAnswerStruct `inject:""`
		B *TypeNestedStruct `inject:"private"`
	}

	if err := inject.Populate(&v); err != nil {
		fmt.Println(err)
	}
	fmt.Printf("%#v", v)
	fmt.Println(v)
	fmt.Println(v.A)
	fmt.Println(v.B)
	fmt.Println(v.B.A == v.A)

}
Exemplo n.º 28
0
func RequireTag() {
	var v struct {
		A *TypeAnswerStruct
		B *TypeNestedStruct `inject:""`
	}

	if err := inject.Populate(&v); err != nil {
		fmt.Println(err)
	}
	fmt.Println(v)
	if v.A != nil {
		glog.Fatal("v.A is not nil")
	}
	if v.B == nil {
		glog.Fatal("v.B is nil")
	}
}
Exemplo n.º 29
0
func TestDoesNotOverwriteInterface(t *testing.T) {
	a := &TypeAnswerStruct{}
	var v struct {
		A Answerable        `inject:""`
		B *TypeNestedStruct `inject:""`
	}
	v.A = a
	if err := inject.Populate(&v); err != nil {
		t.Fatal(err)
	}
	if v.A != a {
		t.Fatal("original A was lost")
	}
	if v.B == nil {
		t.Fatal("v.B is nil")
	}
}
Exemplo n.º 30
0
func InjectSimple() {
	var v struct {
		A *TypeAnswerStruct `inject:""`
		B *TypeNestedStruct `inject:""`
	}

	if err := inject.Populate(&v); err != nil {
		fmt.Println(err)
	}
	fmt.Println(v)
	fmt.Println(v.A)
	fmt.Println(v.B)
	fmt.Println(v.B.A)
	if v.A == v.B.A {
		fmt.Println("wwwwwwww")
	}
}