require 'spec_helper'

describe 'collectd::plugin::dpdk_telemetry', type: :class do
  on_supported_os(baseline_os_hash).each do |os, facts|
    context "on #{os} " do
      let :facts do
        facts
      end

      options = os_specific_options(facts)

      context ':ensure => present, default params' do
        content = <<EOS
# Generated by Puppet
<LoadPlugin dpdk_telemetry>
  Globals false
</LoadPlugin>

<Plugin dpdk_telemetry>
  ClientSocketPath "/var/run/.client"
  DpdkSocketPath "/var/run/dpdk/rte/telemetry"
</Plugin>

EOS

        it "Will create #{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf" do
          is_expected.to compile.with_all_deps
          is_expected.to contain_file('dpdk_telemetry.load').with(
            ensure: 'present',
            path: "#{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf",
            content: content
          )
        end
      end

      context ':ensure => absent' do
        let :params do
          { ensure: 'absent' }
        end

        it "Will not create #{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf" do
          is_expected.to compile.with_all_deps
          is_expected.to contain_file('dpdk_telemetry.load').with(
            ensure: 'absent',
            path: "#{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf"
          )
        end
      end

      context ':ensure => present and :client_socket_path => /test/path/.client' do
        let :params do
          { client_socket_path: '/test/path/.client' }
        end

        it "Will create #{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf" do
          is_expected.to compile.with_all_deps
          is_expected.to contain_file('dpdk_telemetry.load').with(
            ensure: 'present',
            path: "#{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf",
            content: %r{ClientSocketPath "/test/path/.client"}m
          )
        end
      end

      context ':ensure => present and :dpdk_socket_path => /test/path/telemetry' do
        let :params do
          { dpdk_socket_path: '/test/path/telemetry' }
        end

        it "Will create #{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf" do
          is_expected.to compile.with_all_deps
          is_expected.to contain_file('dpdk_telemetry.load').with(
            ensure: 'present',
            path: "#{options[:plugin_conf_dir]}/10-dpdk_telemetry.conf",
            content: %r{DpdkSocketPath "/test/path/telemetry"}m
          )
        end
      end
    end
  end
end
