** Copyright (C) 2001-2025 Zabbix SIA
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"golang.zabbix.com/sdk/uri"
func Test_getParameters(t *testing.T) {
{"+only_hostname", args{[]string{"example.com"}}, "example.com", "443", "example.com", false},
{"+only_ip", args{[]string{"127.0.0.1"}}, "127.0.0.1", "443", "127.0.0.1", false},
{"+full", args{[]string{"example.com", "443", "127.0.0.1"}}, "127.0.0.1", "443", "example.com", false},
{"+empty_port", args{[]string{"example.com", "", "127.0.0.1"}}, "127.0.0.1", "443", "example.com", false},
{"+empty_port_and_ip", args{[]string{"example.com", "", ""}}, "example.com", "443", "example.com", false},
{"+two_params", args{[]string{"example.com", "443"}}, "example.com", "443", "example.com", false},
{"+two_params_port_with_host", args{[]string{"example.com:443", ""}}, "example.com", "443", "example.com", false},
{"+two_params_full", args{[]string{"example.com:443", "443"}}, "example.com", "443", "example.com", false},
{"-full_ipv6", args{[]string{"example.com", "443", "::1"}}, "", "", "", true},
{"-full_ipv6_first", args{[]string{"::1", "443", ""}}, "", "", "", true},
{"-too_many_params", args{[]string{"example.com", "443", "127.0.0.1", "foobar"}}, "", "", "", true},
{"-too_few_params", args{[]string{}}, "", "", "", true},
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotHostname, gotPort, gotDomain, err := getParameters(tt.args.params)
if (err != nil) != tt.wantErr {
t.Errorf("getParameters() error = %v, wantErr %v", err, tt.wantErr)
if gotHostname != tt.wantHostname {
t.Errorf("getParameters() gotHostname = %v, want %v", gotHostname, tt.wantHostname)
if gotPort != tt.wantPort {