File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed
lib/puppet/provider/zabbix_hostgroup
spec/unit/puppet/provider/zabbix_hostgroup Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 22Puppet ::Type . type ( :zabbix_hostgroup ) . provide ( :ruby , parent : Puppet ::Provider ::Zabbix ) do
33 confine feature : :zabbixapi
44
5+ def self . instances
6+ api_hostgroups = zbx . hostgroups . all
7+ api_hostgroups . map do |group_name , _id |
8+ new (
9+ ensure : :present ,
10+ name : group_name
11+ )
12+ end
13+ end
14+
15+ def self . prefetch ( resources )
16+ instances . each do |prov |
17+ if ( resource = resources [ prov . name ] )
18+ resource . provider = prov
19+ end
20+ end
21+ end
22+
523 def create
624 # Connect to zabbix api
725 hgid = zbx . hostgroups . create ( name : @resource [ :name ] )
826 hgid
927 end
1028
1129 def exists?
12- zbx . hostgroups . get_id ( name : @resource [ :name ] )
30+ @property_hash [ :ensure ] == :present
1331 end
1432
1533 def destroy
Original file line number Diff line number Diff line change 1+ require 'spec_helper'
2+
3+ describe Puppet ::Type . type ( :zabbix_hostgroup ) . provider ( :ruby ) do
4+ let ( :resource ) do
5+ Puppet ::Type . type ( :zabbix_hostgroup ) . new (
6+ name : 'Testgroup'
7+ )
8+ end
9+ let ( :provider ) { resource . provider }
10+
11+ it 'be an instance of the correct provider' do
12+ expect ( provider ) . to be_an_instance_of Puppet ::Type ::Zabbix_hostgroup ::ProviderRuby
13+ end
14+
15+ [ :instances , :prefetch ] . each do |method |
16+ it "should respond to the class method #{ method } " do
17+ expect ( described_class ) . to respond_to ( method )
18+ end
19+ end
20+
21+ [ :create , :exists? , :destroy ] . each do |method |
22+ it "should respond to the instance method #{ method } " do
23+ expect ( described_class . new ) . to respond_to ( method )
24+ end
25+ end
26+ end
You can’t perform that action at this time.
0 commit comments