Ember+ loadable plugin
Source
xxxxxxxxxx
/*
** Copyright (C) 2001-2024 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
package plugin
import (
"testing"
"github.com/google/go-cmp/cmp"
"golang.zabbix.com/plugin/ember-plus/ember"
"golang.zabbix.com/sdk/errs"
)
func Test_withJSONResponse(t *testing.T) {
t.Parallel()
type args struct {
handler handlerFunc
}
tests := []struct {
name string
args args
want any
wantErr bool
}{
{
"+valid",
args{
func(metricParams map[string]string, extraParams ...string) (any, error) {
coll := ember.ElementCollection{
ember.ElementKey{
ID: "ID",
Path: "1.2.3",
}: &ember.Element{
Path: "1.2.3",
ElementType: "node",
IsOnline: true,
IsRoot: false,
Maximum: 1,
ValueType: 2,
},
}
return coll, nil
},
},
`{"1.2.3":` + `{"path":"1.2.3","element_type":"node","children":null,"identifier":"","description":"",` +
`"is_online":true,"is_root":false}}`,
false,
},
{
"-handlerErr",
args{
func(metricParams map[string]string, extraParams ...string) (any, error) {
return nil, errs.New("failed")
},
},
nil,
true,
},
{
"-marshalErr",
args{
func(metricParams map[string]string, extraParams ...string) (any, error) {
coll := ember.ElementCollection{
ember.ElementKey{
ID: "ID",
Path: "1.2.3",
}: &ember.Element{
Path: "1.2.3",
ElementType: "foobar",
},
}
return coll, nil
},
},
nil,
true,