summaryrefslogtreecommitdiffstats
path: root/src/go/plugin/go.d/agent/module/mock_test.go
blob: d7521911fc98fb1d9b864cdf39b4727f34555b2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: GPL-3.0-or-later

package module

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestMockModule_Init(t *testing.T) {
	m := &MockModule{}

	assert.NoError(t, m.Init())
	m.InitFunc = func() error { return nil }
	assert.NoError(t, m.Init())
}

func TestMockModule_Check(t *testing.T) {
	m := &MockModule{}

	assert.NoError(t, m.Check())
	m.CheckFunc = func() error { return nil }
	assert.NoError(t, m.Check())
}

func TestMockModule_Charts(t *testing.T) {
	m := &MockModule{}
	c := &Charts{}

	assert.Nil(t, m.Charts())
	m.ChartsFunc = func() *Charts { return c }
	assert.True(t, c == m.Charts())
}

func TestMockModule_Collect(t *testing.T) {
	m := &MockModule{}
	d := map[string]int64{
		"1": 1,
	}

	assert.Nil(t, m.Collect())
	m.CollectFunc = func() map[string]int64 { return d }
	assert.Equal(t, d, m.Collect())
}

func TestMockModule_Cleanup(t *testing.T) {
	m := &MockModule{}
	require.False(t, m.CleanupDone)

	m.Cleanup()
	assert.True(t, m.CleanupDone)
}