PostgreSQL loadable plugin
Source
args{keyCustomQuery, []string{pgAddr, pgUser, pgPwd, pgDb, "TestQuery", "echo"}, nil},
//go:build postgresql_tests
// +build postgresql_tests
/*
** Zabbix
** Copyright 2001-2024 Zabbix SIA
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**/
package plugin
import (
"os"
"reflect"
"testing"
"github.com/omeid/go-yarn"
"golang.zabbix.com/sdk/log"
"golang.zabbix.com/sdk/plugin"
)
var testParamDatabase = map[string]string{"Database": "postgres"}
// TestMain does the before and after setup
func TestMain(m *testing.M) {
var code int
_ = log.Open(log.Console, log.Debug, "", 0)
log.Infof("[TestMain] Start connecting to PostgreSQL...")
if err := createConnection(); err != nil {
log.Infof("failed to create connection to PostgreSQL for tests")
os.Exit(code)
}
// initialize plugin
Impl.Init(Name)
Impl.Configure(&plugin.GlobalOptions{Timeout: 30}, nil)
code = m.Run()
if code != 0 {
log.Critf("failed to run PostgreSQL tests")
os.Exit(code)
}
log.Infof("[TestMain] Cleaning up...")
os.Exit(code)
}
func TestPlugin_Start(t *testing.T) {
t.Run("Connection manager must be initialized", func(t *testing.T) {
Impl.Start()
if Impl.connMgr == nil {
t.Error("Connection manager is not initialized")