registry_test.go 4.6 KB
Newer Older
W
wangzelin.wzl 已提交
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
// Copyright (c) 2021 OceanBase
// obagent is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//
// http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.

package plugins

import (
	"testing"

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

func TestRegisterInput(t *testing.T) {
	InputManager := GetInputManager()
	delete(InputManager.Registry, "test")
	InputManager.Register("test", func() Input {
		return nil
	})
	_, found := InputManager.Registry["test"]
	require.True(t, found)
}

func TestRegisterProcessor(t *testing.T) {
	ProcessorManager := GetProcessorManager()
	delete(ProcessorManager.Registry, "test")
	ProcessorManager.Register("test", func() Processor {
		return nil
	})
	_, found := ProcessorManager.Registry["test"]
	require.True(t, found)
}

func TestRegisterOutput(t *testing.T) {
	OutputManager := GetOutputManager()
	delete(OutputManager.Registry, "test")
	OutputManager.Register("test", func() Output {
		return nil
	})
	_, found := OutputManager.Registry["test"]
	require.True(t, found)
}

func TestRegisterExporter(t *testing.T) {
	exporterManager := GetExporterManager()
	delete(exporterManager.Registry, "test")
	exporterManager.Register("test", func() Exporter {
		return nil
	})
	_, found := exporterManager.Registry["test"]
	require.True(t, found)
}

func TestRegisterInputAgain(t *testing.T) {
	defer func() { recover() }()
	InputManager := GetInputManager()
	delete(InputManager.Registry, "test")
	for i := 0; i < 2; i++ {
		InputManager.Register("test", func() Input {
			return nil
		})
	}
	t.Errorf("Register input should panic")
}

func TestRegisterProcessorAgain(t *testing.T) {
	defer func() { recover() }()
	ProcessorManager := GetProcessorManager()
	delete(ProcessorManager.Registry, "test")
	for i := 0; i < 2; i++ {
		ProcessorManager.Register("test", func() Processor {
			return nil
		})
	}
	t.Errorf("Register processor should panic")
}

func TestRegisterOutputAgain(t *testing.T) {
	defer func() { recover() }()
	OutputManager := GetOutputManager()
	delete(OutputManager.Registry, "test")
	for i := 0; i < 2; i++ {
		OutputManager.Register("test", func() Output {
			return nil
		})
	}
	t.Errorf("Register output should panic")
}

func TestRegisterExporterAgain(t *testing.T) {
	defer func() { recover() }()
	exporterManager := GetExporterManager()
	delete(exporterManager.Registry, "test")
	for i := 0; i < 2; i++ {
		exporterManager.Register("test", func() Exporter {
			return nil
		})
	}
	t.Errorf("Register exporter should panic")
}

func TestGetInput(t *testing.T) {
	InputManager := GetInputManager()
	delete(InputManager.Registry, "test")
	InputManager.Register("test", func() Input {
		return nil
	})
	_, err := InputManager.GetPlugin("test")
	require.True(t, err == nil)
}

func TestGetProcessor(t *testing.T) {
	ProcessorManager := GetProcessorManager()
	delete(ProcessorManager.Registry, "test")
	ProcessorManager.Register("test", func() Processor {
		return nil
	})
	_, err := ProcessorManager.GetPlugin("test")
	require.True(t, err == nil)
}

func TestGetOutput(t *testing.T) {
	OutputManager := GetOutputManager()
	delete(OutputManager.Registry, "test")
	OutputManager.Register("test", func() Output {
		return nil
	})
	_, err := OutputManager.GetPlugin("test")
	require.True(t, err == nil)
}

func TestGetExporter(t *testing.T) {
	exporterManager := GetExporterManager()
	delete(exporterManager.Registry, "test")
	exporterManager.Register("test", func() Exporter {
		return nil
	})
	_, err := exporterManager.GetPlugin("test")
	require.True(t, err == nil)
}

func TestGetInputNotExists(t *testing.T) {
	InputManager := GetInputManager()
	delete(InputManager.Registry, "test")
	_, err := InputManager.GetPlugin("test")
	require.True(t, err != nil)
}

func TestGetProcessorNotExists(t *testing.T) {
	ProcessorManager := GetProcessorManager()
	delete(ProcessorManager.Registry, "test")
	_, err := ProcessorManager.GetPlugin("test")
	require.True(t, err != nil)
}

func TestGetOutputNotExists(t *testing.T) {
	OutputManager := GetOutputManager()
	delete(OutputManager.Registry, "test")
	_, err := OutputManager.GetPlugin("test")
	require.True(t, err != nil)
}

func TestGetExporterNotExists(t *testing.T) {
	exporterManager := GetExporterManager()
	delete(exporterManager.Registry, "test")
	_, err := exporterManager.GetPlugin("test")
	require.True(t, err != nil)
}