Exemple #1
0
func TestErrorWire(t *testing.T) {
	var pico = picodi.New()
	if err := pico.Wire(&Bar{}); err == nil {
		t.Fatal("Expected error for missing provider, nothing")
	}

}
Exemple #2
0
func TestStructWire(t *testing.T) {
	var pico = picodi.New()
	pico.SetValue("fooptr", &Foo{"Foo"})
	pico.SetValue("foo", Foo{"Foo"})
	pico.SetValue("Foo", Foo{"Foo"}) // unnamed wire
	pico.Set("foofn", func() interface{} {
		return Foo{"FooFn"}
	})
	var bar = Bar{}
	if err := pico.Wire(&bar); err != nil {
		t.Fatal("Unexpected error when wiring bar: ", err)
	}

	if bar.Foo.Name() != "Foo" {
		t.Fatal("Expected \"Foo\" for Foo, got", bar.Foo.Name())
	}

	if bar.FooPtr.Name() != "Foo" {
		t.Fatal("Expected \"Foo\" for FooPtr, got", bar.FooPtr.Name())
	}

	if bar.Other.Name() != "Foo" {
		t.Fatal("Expected \"Foo\" for Other, got", bar.Other.Name())
	}

	if bar.Foo2.Name() != "Foo" {
		t.Fatal("Expected \"Foo\" for Foo2, got", bar.Foo2.Name())
	}

	if bar.inner.Name() != "Foo" {
		t.Fatal("Expected \"Foo\" for inner, got", bar.inner.Name())
	}

	if bar.Fun.Name() != "FooFn" {
		t.Fatal("Expected \"FooFn\" for Fun, got", bar.Fun.Name())
	}
}