0

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 https://supermarket.chef.io/cookbooks/kafka. 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!

Stenio Ferreira
  • 357
  • 2
  • 10

1 Answers1

0

Two parts to the answer: first ChefSpec is used for unit testing, and is unrelated to Test Kitchen and integration testing. Second, you would need to make a minimal test recipe to install a 1-node ZK server and use that for integration testing. Generally you would do this by putting a test cookbook under test/cookbook and then add it to your Berksfile with a path source. You could use a "real" ZK cookbook, or you could use something simpler and more dedicated. Just an example of minimalism for testing, see my MongoDB recipe. You can probably use something similar for ZK in this situation.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Thank you for your answer, and kudos on the application cookbook! I am working with a .Net project, will see if I can use your cookbook instead of the sequence of powershell commands I am using currently. Regarding the testing, I prefer to avoid your approach of including the dependent recipe in the main recipe just for the sake of tests. However I will try doing the test/cookbook and see if it solves the problem. Update soon. Cheers! – Stenio Ferreira May 14 '16 at 16:57