diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 08:15:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 08:15:20 +0000 |
commit | 87d772a7d708fec12f48cd8adc0dedff6e1025da (patch) | |
tree | 1fee344c64cc3f43074a01981e21126c8482a522 /src/go/collectors/go.d.plugin/agent/functions/manager_test.go | |
parent | Adding upstream version 1.46.3. (diff) | |
download | netdata-upstream.tar.xz netdata-upstream.zip |
Adding upstream version 1.47.0.upstream/1.47.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/go/plugin/go.d/agent/functions/manager_test.go (renamed from src/go/collectors/go.d.plugin/agent/functions/manager_test.go) | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/go/collectors/go.d.plugin/agent/functions/manager_test.go b/src/go/plugin/go.d/agent/functions/manager_test.go index 26a8cdd0c..c19519bc1 100644 --- a/src/go/collectors/go.d.plugin/agent/functions/manager_test.go +++ b/src/go/plugin/go.d/agent/functions/manager_test.go @@ -3,6 +3,7 @@ package functions import ( + "bufio" "context" "sort" "strings" @@ -15,7 +16,7 @@ import ( func TestNewManager(t *testing.T) { mgr := NewManager() - assert.NotNilf(t, mgr.Input, "Input") + assert.NotNilf(t, mgr.input, "Input") assert.NotNilf(t, mgr.FunctionRegistry, "FunctionRegistry") } @@ -261,7 +262,7 @@ FUNCTION_PAYLOAD_END t.Run(name, func(t *testing.T) { mgr := NewManager() - mgr.Input = strings.NewReader(test.input) + mgr.input = newMockInput(test.input) mock := &mockFunctionExecutor{} for _, v := range test.register { @@ -297,3 +298,23 @@ type mockFunctionExecutor struct { func (m *mockFunctionExecutor) execute(fn Function) { m.executed = append(m.executed, fn) } + +func newMockInput(data string) *mockInput { + m := &mockInput{chLines: make(chan string)} + sc := bufio.NewScanner(strings.NewReader(data)) + go func() { + for sc.Scan() { + m.chLines <- sc.Text() + } + close(m.chLines) + }() + return m +} + +type mockInput struct { + chLines chan string +} + +func (m *mockInput) lines() chan string { + return m.chLines +} |