# InSpec test for cli

# Get node attributes
nodes_dir = '/tmp/kitchen/nodes'
output = command("ls #{nodes_dir}").stdout.strip
node_json = "#{nodes_dir}/#{output}"
if file(node_json).exist?
  node = json(node_json).params

  describe file "#{node['default']['snowflake']['cli']['destination']}/#{node['default']['snowflake']['cli']['name']}" do
    it { should exist }
    it { should be_allowed('execute') }
  end

  describe directory node['default']['snowflake']['cli']['config_file_location'] do
    it { should exist }
    its('owner') { should eq node['default']['snowflake']['cli']['user'] }
    its('mode') { should cmp '0700' }
  end
else
  puts "File #{node_json} does not exist - skipping attribute-dependent checks"
end
