Sha256: b3d93317a43721ee5e1fce8f6b813ccc59317605ca722667796883808c2a7067

Contents?: true

Size: 760 Bytes

Versions: 3

Compression:

Stored size: 760 Bytes

Contents

require 'serverspec'
require 'serverspec/type/base'

module Serverspec::Type
  class ChocolateyPackage < Base

    def initialize(name)
      @name = name
      @runner = Specinfra::Runner
    end

    def installed?(provider, version)
      command_result = @runner.run_command("choco list -l -r #{name}")

      software = command_result.stdout.gsub("\r\n", "\n").split("\n").each_with_object({}) do |s, h|
        v, k = s.split('|')
        h[String(v).strip.downcase] = String(k).strip.downcase
        h
      end

      if (version.nil?)
        !software[name.downcase].nil?
      else
        software[name.downcase] == version
      end
    end
  end

  def chocolatey_package(name)
    ChocolateyPackage.new(name)
  end
end

include Serverspec::Type

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
octopus-serverspec-extensions-0.19.1 lib/octopus_serverspec_extensions/type/chocolatey_package.rb
octopus-serverspec-extensions-0.19.0 lib/octopus_serverspec_extensions/type/chocolatey_package.rb
octopus-serverspec-extensions-0.14.0 lib/octopus_serverspec_extensions/type/chocolatey_package.rb