master
go 60 lines 1.25 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package collectorapi
4
5 import (
6 "context"
7 "testing"
8
9 "github.com/stretchr/testify/assert"
10 "github.com/stretchr/testify/require"
11 )
12
13 func TestMockModule_Init(t *testing.T) {
14 m := &MockCollectorV1{}
15 ctx := context.Background()
16
17 assert.NoError(t, m.Init(ctx))
18 m.InitFunc = func(context.Context) error { return nil }
19 assert.NoError(t, m.Init(ctx))
20 }
21
22 func TestMockModule_Check(t *testing.T) {
23 m := &MockCollectorV1{}
24 ctx := context.Background()
25
26 assert.NoError(t, m.Check(ctx))
27 m.CheckFunc = func(context.Context) error { return nil }
28 assert.NoError(t, m.Check(ctx))
29 }
30
31 func TestMockModule_Charts(t *testing.T) {
32 m := &MockCollectorV1{}
33 c := &Charts{}
34
35 assert.Nil(t, m.Charts())
36 m.ChartsFunc = func() *Charts { return c }
37 assert.True(t, c == m.Charts())
38 }
39
40 func TestMockModule_Collect(t *testing.T) {
41 m := &MockCollectorV1{}
42 d := map[string]int64{
43 "1": 1,
44 }
45 ctx := context.Background()
46
47 assert.Nil(t, m.Collect(ctx))
48 m.CollectFunc = func(ctx context.Context) map[string]int64 { return d }
49 assert.Equal(t, d, m.Collect(ctx))
50 }
51
52 func TestMockModule_Cleanup(t *testing.T) {
53 m := &MockCollectorV1{}
54 ctx := context.Background()
55
56 require.False(t, m.CleanupDone)
57
58 m.Cleanup(ctx)
59 assert.True(t, m.CleanupDone)
60 }