summaryrefslogtreecommitdiff
path: root/plugins/app/tests/factory_test.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2020-10-26 21:02:56 +0300
committerWolfy-J <[email protected]>2020-10-26 21:02:56 +0300
commit2d3349eee632e7357ed1eb6905444194a28a4ec0 (patch)
tree74e15277ffe8c11a24e3d3b1a30edfd9597ef984 /plugins/app/tests/factory_test.go
parent91cf918b30938129609323ded53e190385e019a6 (diff)
- working on new cmd and logger setup
Diffstat (limited to 'plugins/app/tests/factory_test.go')
-rw-r--r--plugins/app/tests/factory_test.go78
1 files changed, 78 insertions, 0 deletions
diff --git a/plugins/app/tests/factory_test.go b/plugins/app/tests/factory_test.go
new file mode 100644
index 00000000..7c885797
--- /dev/null
+++ b/plugins/app/tests/factory_test.go
@@ -0,0 +1,78 @@
+package tests
+
+import (
+ "os"
+ "os/signal"
+ "testing"
+ "time"
+
+ "github.com/spiral/endure"
+ "github.com/spiral/roadrunner/v2/plugins/app"
+ "github.com/spiral/roadrunner/v2/plugins/config"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestFactory(t *testing.T) {
+ container, err := endure.NewContainer(endure.DebugLevel, endure.RetryOnFail(true))
+ if err != nil {
+ t.Fatal(err)
+ }
+ // config plugin
+ vp := &config.ViperProvider{}
+ vp.Path = ".rr.yaml"
+ vp.Prefix = "rr"
+ err = container.Register(vp)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = container.Register(&app.App{})
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = container.Register(&Foo{})
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = container.Register(&Foo2{})
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = container.Init()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ errCh, err := container.Serve()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // stop by CTRL+C
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, os.Interrupt)
+
+ tt := time.NewTicker(time.Second * 2)
+
+ for {
+ select {
+ case e := <-errCh:
+ assert.NoError(t, e.Error)
+ assert.NoError(t, container.Stop())
+ return
+ case <-c:
+ er := container.Stop()
+ if er != nil {
+ panic(er)
+ }
+ return
+ case <-tt.C:
+ tt.Stop()
+ assert.NoError(t, container.Stop())
+ return
+ }
+ }
+}