dimanche 8 mai 2016

Test Kitchen integration tests with Chefspec: testing cookbook with dependencies

I understand that Test Kitchen follows the sequence

create node > converge cookbook > run tests

What is the best practice to create a test that assumes a strong external dependency?

An example is the Kafka cookbook http://ift.tt/1T5rlMs. As you might know, Kafka is a messaging broker application that depends on Zookeeper, a separate application that is the message hub.

Following proper separation of concerns, the Kafka cookbook does not include Zookeeper - it can be installed in the same host or in a different machine.

However in order to do a simple verification if Kafka is working, (i.e. create a simple message), you need to have a Zookeeper server running.

For example, the test could be running these three commands after installation

# creates a message topic
bin/kafka-create-topic.sh --zookeeper localhost:2181 --replica 1 --partition 1 --topic test

# lists existing message topics
bin/kafka-list-topic.sh --zookeeper localhost:2181

# sends a message to this machine
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

Using Chefspec, is there a way to stub this external server (the localhost:2181 part above)?

Thank you!

Aucun commentaire:

Enregistrer un commentaire