2018-12-07 10:13:53 +01:00
|
|
|
package container
|
2018-12-06 15:18:05 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"forge.cadoles.com/wpetit/goweb/service"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestContextServiceContainer(t *testing.T) {
|
|
|
|
|
|
|
|
container := service.NewContainer()
|
|
|
|
ctx := context.WithValue(context.Background(), KeyServiceContainer, container)
|
|
|
|
|
2018-12-07 10:13:53 +01:00
|
|
|
ctn, err := From(ctx)
|
2018-12-06 15:18:05 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctn == nil {
|
|
|
|
t.Fatal("container should not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContextInvalidServiceContainer(t *testing.T) {
|
|
|
|
|
|
|
|
invalidContainer := struct{}{}
|
|
|
|
ctx := context.WithValue(context.Background(), KeyServiceContainer, invalidContainer)
|
|
|
|
|
2018-12-07 10:13:53 +01:00
|
|
|
container, err := From(ctx)
|
2018-12-06 15:18:05 +01:00
|
|
|
|
|
|
|
if g, e := err, ErrInvalidServiceContainer; g != e {
|
|
|
|
t.Errorf("err: got '%v', expected '%v'", g, e)
|
|
|
|
}
|
|
|
|
|
|
|
|
if container != nil {
|
|
|
|
t.Errorf("container: got '%v', expected '%v'", container, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|