diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:18 +0000 |
commit | 5da14042f70711ea5cf66e034699730335462f66 (patch) | |
tree | 0f6354ccac934ed87a2d555f45be4c831cf92f4a /src/go/collectors/go.d.plugin/modules/unbound/config/parse_test.go | |
parent | Releasing debian version 1.44.3-2. (diff) | |
download | netdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz netdata-5da14042f70711ea5cf66e034699730335462f66.zip |
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/unbound/config/parse_test.go | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/unbound/config/parse_test.go b/src/go/collectors/go.d.plugin/modules/unbound/config/parse_test.go new file mode 100644 index 000000000..72542a861 --- /dev/null +++ b/src/go/collectors/go.d.plugin/modules/unbound/config/parse_test.go @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package config + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestParse(t *testing.T) { + tests := map[string]struct { + path string + wantCfg UnboundConfig + wantErr bool + }{ + "valid include": { + path: "testdata/valid_include.conf", + wantCfg: UnboundConfig{ + cumulative: "yes", + enable: "yes", + iface: "10.0.0.1", + port: "8955", + useCert: "yes", + keyFile: "/etc/unbound/unbound_control_2.key", + certFile: "/etc/unbound/unbound_control_2.pem", + }, + }, + "valid include-toplevel": { + path: "testdata/valid_include_toplevel.conf", + wantCfg: UnboundConfig{ + cumulative: "yes", + enable: "yes", + iface: "10.0.0.1", + port: "8955", + useCert: "yes", + keyFile: "/etc/unbound/unbound_control_2.key", + certFile: "/etc/unbound/unbound_control_2.pem", + }, + }, + "valid glob include": { + path: "testdata/valid_glob.conf", + wantCfg: UnboundConfig{ + cumulative: "yes", + enable: "yes", + iface: "10.0.0.1", + port: "8955", + useCert: "yes", + keyFile: "/etc/unbound/unbound_control_2.key", + certFile: "/etc/unbound/unbound_control_2.pem", + }, + }, + "non existent glob include": { + path: "testdata/non_existent_glob_include.conf", + wantCfg: UnboundConfig{ + cumulative: "yes", + enable: "yes", + iface: "10.0.0.1", + port: "8953", + useCert: "yes", + keyFile: "/etc/unbound/unbound_control.key", + certFile: "/etc/unbound/unbound_control.pem", + }, + }, + "infinite recursion include": { + path: "testdata/infinite_rec.conf", + wantErr: true, + }, + "non existent include": { + path: "testdata/non_existent_include.conf", + wantErr: true, + }, + "non existent path": { + path: "testdata/non_existent_path.conf", + wantErr: true, + }, + } + + for name, test := range tests { + name = fmt.Sprintf("%s (%s)", name, test.path) + t.Run(name, func(t *testing.T) { + cfg, err := Parse(test.path) + + if test.wantErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, test.wantCfg, *cfg) + } + }) + } +} |