From 0c3a694470c0238cd69769a516e9481cfc7114de Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Thu, 11 Oct 2018 17:46:41 +0200 Subject: [PATCH] fixup: add test for global section --- config/config_global_test.go | 82 ++++++++++++++++++++++++++++++++++++ config/config_test.go | 13 +----- 2 files changed, 83 insertions(+), 12 deletions(-) create mode 100644 config/config_global_test.go diff --git a/config/config_global_test.go b/config/config_global_test.go new file mode 100644 index 0000000..50948b7 --- /dev/null +++ b/config/config_global_test.go @@ -0,0 +1,82 @@ +package config + +import ( + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/zrepl/yaml-config" + "testing" +) + +func testValidGlobalSection(t *testing.T, s string) *Config { + jobdef := ` +jobs: +- name: dummyjob + type: sink + serve: + type: tcp + listen: ":2342" + clients: { + "10.0.0.1":"foo" + } + root_dataset: zoot/foo +` + _, err := ParseConfigBytes([]byte(jobdef)) + require.NoError(t, err) + return testValidConfig(t, s + jobdef) +} + +func TestOutletTypes(t *testing.T) { + conf := testValidGlobalSection(t, ` +global: + logging: + - type: stdout + level: debug + format: human + - type: syslog + level: info + retry_interval: 20s + format: human + - type: tcp + level: debug + format: json + address: logserver.example.com:1234 + - type: tcp + level: debug + format: json + address: encryptedlogserver.example.com:1234 + retry_interval: 20s + tls: + ca: /etc/zrepl/log/ca.crt + cert: /etc/zrepl/log/key.pem + key: /etc/zrepl/log/cert.pem +`) + assert.Equal(t, 4, len(*conf.Global.Logging)) + assert.NotNil(t, (*conf.Global.Logging)[3].Ret.(*TCPLoggingOutlet).TLS) +} + +func TestDefaultLoggingOutlet(t *testing.T) { + conf := testValidGlobalSection(t, "") + assert.Equal(t, 1, len(*conf.Global.Logging)) + o := (*conf.Global.Logging)[0].Ret.(StdoutLoggingOutlet) + assert.Equal(t, "warn", o.Level) + assert.Equal(t, "human", o.Format) +} + +func TestPrometheusMonitoring(t *testing.T) { + conf := testValidGlobalSection(t, ` +global: + monitoring: + - type: prometheus + listen: ':9091' +`) + assert.Equal(t, ":9091", conf.Global.Monitoring[0].Ret.(*PrometheusMonitoring).Listen) +} + +func TestLoggingOutletEnumList_SetDefaults(t *testing.T) { + e := &LoggingOutletEnumList{} + var i yaml.Defaulter = e + require.NotPanics(t, func() { + i.SetDefault() + assert.Equal(t, "warn", (*e)[0].Ret.(StdoutLoggingOutlet).Level) + }) +} diff --git a/config/config_test.go b/config/config_test.go index 07bbbb8..d8e1e2c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -2,12 +2,10 @@ package config import ( "github.com/kr/pretty" + "github.com/stretchr/testify/require" "path" "path/filepath" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/zrepl/yaml-config" ) func TestSampleConfigsAreParsedWithoutErrors(t *testing.T) { @@ -37,15 +35,6 @@ func TestSampleConfigsAreParsedWithoutErrors(t *testing.T) { } -func TestLoggingOutletEnumList_SetDefaults(t *testing.T) { - e := &LoggingOutletEnumList{} - var i yaml.Defaulter = e - require.NotPanics(t, func() { - i.SetDefault() - assert.Equal(t, "warn", (*e)[0].Ret.(StdoutLoggingOutlet).Level) - }) -} - func testValidConfig(t *testing.T, input string) (*Config) { t.Helper()