diff options
author | Valery Piashchynski <[email protected]> | 2020-10-13 13:55:20 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-10-13 13:55:20 +0300 |
commit | 0dc44d54cfcc9dd3fa09a41136f35a9a8d26b994 (patch) | |
tree | ffcb65010bebe9f5b5436192979e64b2402a6ec0 /plugins/config/tests | |
parent | 08d6b6b7f773f83b286cd48c1a0fbec9a62fb42b (diff) |
Initial commit of RR 2.0v2.0.0-alpha1
Diffstat (limited to 'plugins/config/tests')
-rw-r--r-- | plugins/config/tests/.rr.yaml | 28 | ||||
-rw-r--r-- | plugins/config/tests/config_test.go | 67 | ||||
-rw-r--r-- | plugins/config/tests/plugin1.go | 54 |
3 files changed, 149 insertions, 0 deletions
diff --git a/plugins/config/tests/.rr.yaml b/plugins/config/tests/.rr.yaml new file mode 100644 index 00000000..df9077d0 --- /dev/null +++ b/plugins/config/tests/.rr.yaml @@ -0,0 +1,28 @@ +reload: + # enable or disable file watcher + enabled: true + # sync interval + interval: 1s + # global patterns to sync + patterns: [".php"] + # list of included for sync services + services: + http: + # recursive search for file patterns to add + recursive: true + # ignored folders + ignore: ["vendor"] + # service specific file pattens to sync + patterns: [".php", ".go",".md",] + # directories to sync. If recursive is set to true, + # recursive sync will be applied only to the directories in `dirs` section + dirs: ["."] + jobs: + recursive: false + ignore: ["service/metrics"] + dirs: ["./jobs"] + rpc: + recursive: true + patterns: [".json"] + # to include all project directories from workdir, leave `dirs` empty or add a dot "." + dirs: [""] diff --git a/plugins/config/tests/config_test.go b/plugins/config/tests/config_test.go new file mode 100644 index 00000000..baeafbd2 --- /dev/null +++ b/plugins/config/tests/config_test.go @@ -0,0 +1,67 @@ +package tests + +import ( + "os" + "os/signal" + "testing" + "time" + + "github.com/spiral/endure" + "github.com/stretchr/testify/assert" + "github.com/temporalio/roadrunner-temporal/config" +) + +func TestViperProvider_Init(t *testing.T) { + container, err := endure.NewContainer(endure.DebugLevel, endure.RetryOnFail(true)) + if err != nil { + t.Fatal(err) + } + vp := &config.ViperProvider{} + vp.Path = ".rr.yaml" + vp.Prefix = "rr" + err = container.Register(vp) + if err != nil { + t.Fatal(err) + } + + err = container.Register(&Foo{}) + 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) + signal.Notify(c, os.Interrupt) + + tt := time.NewTicker(time.Second * 2) + + for { + select { + case e := <-errCh: + assert.NoError(t, e.Error.Err) + 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 + } + } + +} diff --git a/plugins/config/tests/plugin1.go b/plugins/config/tests/plugin1.go new file mode 100644 index 00000000..4e7a5317 --- /dev/null +++ b/plugins/config/tests/plugin1.go @@ -0,0 +1,54 @@ +package tests + +import ( + "errors" + "time" + + "github.com/temporalio/roadrunner-temporal/config" +) + +// ReloadConfig is a Reload configuration point. +type ReloadConfig struct { + Interval time.Duration + Patterns []string + Services map[string]ServiceConfig +} + +type ServiceConfig struct { + Enabled bool + Recursive bool + Patterns []string + Dirs []string + Ignore []string +} + +type Foo struct { + configProvider config.Provider +} + + +// Depends on S2 and DB (S3 in the current case) +func (f *Foo) Init(p config.Provider) error { + f.configProvider = p + return nil +} + +func (f *Foo) Serve() chan error { + errCh := make(chan error, 1) + + r := &ReloadConfig{} + err := f.configProvider.UnmarshalKey("reload", r) + if err != nil { + errCh <- err + } + + if len(r.Patterns) == 0 { + errCh <- errors.New("should be at least one pattern, but got 0") + } + + return errCh +} + +func (f *Foo) Stop() error { + return nil +} |