Skip to main content

cassandradb_session resource

Use the cassandradb_session Chef InSpec audit resource to test Cassandra Query Language (CQL) commands run against a Cassandra database.

Availability

Install

This resource is distributed with Chef InSpec and is automatically available for use.

Syntax

A cassandradb_session resource block declares the username, password, host, and port to use for the session, and then the command to be run:

describe cassandradb_session(user: 'USERNAME', password: 'PASSWORD', host: 'localhost', port: 9042).query('QUERY') do
  its('value') { should eq('EXPECTED') }
end

where

  • cassandradb_session declares a username, password, host and port to run the query.
  • query('QUERY') contains the query to be run.
  • its('value') { should eq('expected') } compares the results of the query against the expected result in the test.

Optional Parameters

The cassandradb_session InSpec resource accepts user, password, host, and port parameters.

In Particular:

user

Default value: cassandra.

password

Default value: cassandra.

Examples

The following examples show how to use this Chef InSpec audit resource.

Test for matching values using a Cassandra query

cql = cassandradb_session(user: 'MY_USER', password: 'PASSWORD', host: 'localhost', port: 9042)

describe cql.query("SELECT cluster_name FROM system.local") do
  its('output') { should match /Test Cluster/ }
end

Test for matching values using a Cassandra query from a sample database

cql = cassandradb_session(user: 'MY_USER', password: 'PASSWORD', host: 'localhost', port: 9042)

describe cql.query("use SAMPLEDB; SELECT name FROM SAMPLETABLE") do
  its('output') { should match /Test Name/ }
end

Matchers

For a full list of available matchers, see our Universal Matchers page.
Edit this page on GitHub

Thank you for your feedback!

×