summaryrefslogtreecommitdiff
path: root/internal/container
diff options
context:
space:
mode:
Diffstat (limited to 'internal/container')
-rw-r--r--internal/container/config.go17
-rw-r--r--internal/container/config_test.go33
-rw-r--r--internal/container/test/endure_ok.yaml5
-rw-r--r--internal/container/test/endure_ok_debug.yaml5
-rw-r--r--internal/container/test/endure_ok_fatal.yaml5
-rw-r--r--internal/container/test/endure_ok_foobar.yaml5
-rw-r--r--internal/container/test/endure_ok_info.yaml5
-rw-r--r--internal/container/test/endure_ok_panic.yaml5
-rw-r--r--internal/container/test/endure_ok_warn.yaml5
-rw-r--r--internal/container/test/without_endure_ok.yaml0
10 files changed, 59 insertions, 26 deletions
diff --git a/internal/container/config.go b/internal/container/config.go
index 149d6b9b..71deafc2 100644
--- a/internal/container/config.go
+++ b/internal/container/config.go
@@ -4,8 +4,8 @@ import (
"fmt"
"time"
- "github.com/roadrunner-server/config/v2"
endure "github.com/roadrunner-server/endure/pkg/container"
+ "github.com/spf13/viper"
)
type Config struct {
@@ -21,8 +21,16 @@ const (
)
// NewConfig creates endure container configuration.
-func NewConfig(cfgPlugin *config.Plugin) (*Config, error) {
- if !cfgPlugin.Has(endureKey) {
+func NewConfig(cfgFile string) (*Config, error) {
+ v := viper.New()
+ v.SetConfigFile(cfgFile)
+
+ err := v.ReadInConfig()
+ if err != nil {
+ return nil, err
+ }
+
+ if !v.IsSet(endureKey) {
return &Config{ // return config with defaults
GracePeriod: defaultGracePeriod,
PrintGraph: false,
@@ -38,7 +46,8 @@ func NewConfig(cfgPlugin *config.Plugin) (*Config, error) {
LogLevel string `mapstructure:"log_level"`
}{}
- if err := cfgPlugin.UnmarshalKey(endureKey, &rrCfgEndure); err != nil {
+ err = v.UnmarshalKey(endureKey, &rrCfgEndure)
+ if err != nil {
return nil, err
}
diff --git a/internal/container/config_test.go b/internal/container/config_test.go
index e20b2d9e..413d1eac 100644
--- a/internal/container/config_test.go
+++ b/internal/container/config_test.go
@@ -4,24 +4,14 @@ import (
"testing"
"time"
- "github.com/roadrunner-server/roadrunner/v2/internal/container"
-
"github.com/roadrunner-server/config/v2"
endure "github.com/roadrunner-server/endure/pkg/container"
+ "github.com/roadrunner-server/roadrunner/v2/internal/container"
"github.com/stretchr/testify/assert"
)
func TestNewConfig_SuccessfulReading(t *testing.T) {
- cfgPlugin := &config.Plugin{Type: "yaml", ReadInCfg: []byte(`
-endure:
- grace_period: 10s
- print_graph: true
- retry_on_fail: true
- log_level: warn
-`)}
- assert.NoError(t, cfgPlugin.Init())
-
- c, err := container.NewConfig(cfgPlugin)
+ c, err := container.NewConfig("test/endure_ok.yaml")
assert.NoError(t, err)
assert.NotNil(t, c)
@@ -35,7 +25,7 @@ func TestNewConfig_WithoutEndureKey(t *testing.T) {
cfgPlugin := &config.Plugin{Type: "yaml", ReadInCfg: []byte{}}
assert.NoError(t, cfgPlugin.Init())
- c, err := container.NewConfig(cfgPlugin)
+ c, err := container.NewConfig("test/without_endure_ok.yaml")
assert.NoError(t, err)
assert.NotNil(t, c)
@@ -47,26 +37,25 @@ func TestNewConfig_WithoutEndureKey(t *testing.T) {
func TestNewConfig_LoggingLevels(t *testing.T) {
for _, tt := range []struct {
+ path string
giveLevel string
wantLevel endure.Level
wantError bool
}{
- {giveLevel: "debug", wantLevel: endure.DebugLevel},
- {giveLevel: "info", wantLevel: endure.InfoLevel},
- {giveLevel: "warn", wantLevel: endure.WarnLevel},
- {giveLevel: "warning", wantLevel: endure.WarnLevel},
- {giveLevel: "error", wantLevel: endure.ErrorLevel},
- {giveLevel: "panic", wantLevel: endure.PanicLevel},
- {giveLevel: "fatal", wantLevel: endure.FatalLevel},
+ {path: "test/endure_ok_debug.yaml", giveLevel: "debug", wantLevel: endure.DebugLevel},
+ {path: "test/endure_ok_info.yaml", giveLevel: "info", wantLevel: endure.InfoLevel},
+ {path: "test/endure_ok_warn.yaml", giveLevel: "warn", wantLevel: endure.WarnLevel},
+ {path: "test/endure_ok_panic.yaml", giveLevel: "panic", wantLevel: endure.PanicLevel},
+ {path: "test/endure_ok_fatal.yaml", giveLevel: "fatal", wantLevel: endure.FatalLevel},
- {giveLevel: "foobar", wantError: true},
+ {path: "test/endure_ok_foobar.yaml", giveLevel: "foobar", wantError: true},
} {
tt := tt
t.Run(tt.giveLevel, func(t *testing.T) {
cfgPlugin := &config.Plugin{Type: "yaml", ReadInCfg: []byte("endure:\n log_level: " + tt.giveLevel)}
assert.NoError(t, cfgPlugin.Init())
- c, err := container.NewConfig(cfgPlugin)
+ c, err := container.NewConfig(tt.path)
if tt.wantError {
assert.Nil(t, c)
diff --git a/internal/container/test/endure_ok.yaml b/internal/container/test/endure_ok.yaml
new file mode 100644
index 00000000..03db7c23
--- /dev/null
+++ b/internal/container/test/endure_ok.yaml
@@ -0,0 +1,5 @@
+endure:
+ grace_period: 10s
+ print_graph: true
+ retry_on_fail: true
+ log_level: warn
diff --git a/internal/container/test/endure_ok_debug.yaml b/internal/container/test/endure_ok_debug.yaml
new file mode 100644
index 00000000..5953c4de
--- /dev/null
+++ b/internal/container/test/endure_ok_debug.yaml
@@ -0,0 +1,5 @@
+endure:
+ grace_period: 10s
+ print_graph: true
+ retry_on_fail: true
+ log_level: debug
diff --git a/internal/container/test/endure_ok_fatal.yaml b/internal/container/test/endure_ok_fatal.yaml
new file mode 100644
index 00000000..69e16467
--- /dev/null
+++ b/internal/container/test/endure_ok_fatal.yaml
@@ -0,0 +1,5 @@
+endure:
+ grace_period: 10s
+ print_graph: true
+ retry_on_fail: true
+ log_level: fatal
diff --git a/internal/container/test/endure_ok_foobar.yaml b/internal/container/test/endure_ok_foobar.yaml
new file mode 100644
index 00000000..90728d2c
--- /dev/null
+++ b/internal/container/test/endure_ok_foobar.yaml
@@ -0,0 +1,5 @@
+endure:
+ grace_period: 10s
+ print_graph: true
+ retry_on_fail: true
+ log_level: foobar
diff --git a/internal/container/test/endure_ok_info.yaml b/internal/container/test/endure_ok_info.yaml
new file mode 100644
index 00000000..7ad62861
--- /dev/null
+++ b/internal/container/test/endure_ok_info.yaml
@@ -0,0 +1,5 @@
+endure:
+ grace_period: 10s
+ print_graph: true
+ retry_on_fail: true
+ log_level: info
diff --git a/internal/container/test/endure_ok_panic.yaml b/internal/container/test/endure_ok_panic.yaml
new file mode 100644
index 00000000..5ac4dc9e
--- /dev/null
+++ b/internal/container/test/endure_ok_panic.yaml
@@ -0,0 +1,5 @@
+endure:
+ grace_period: 10s
+ print_graph: true
+ retry_on_fail: true
+ log_level: panic
diff --git a/internal/container/test/endure_ok_warn.yaml b/internal/container/test/endure_ok_warn.yaml
new file mode 100644
index 00000000..03db7c23
--- /dev/null
+++ b/internal/container/test/endure_ok_warn.yaml
@@ -0,0 +1,5 @@
+endure:
+ grace_period: 10s
+ print_graph: true
+ retry_on_fail: true
+ log_level: warn
diff --git a/internal/container/test/without_endure_ok.yaml b/internal/container/test/without_endure_ok.yaml
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/internal/container/test/without_endure_ok.yaml