I was trying some TDD with [Tesk-Kitchen][1] and [ServerSpec][2] when I found myself in the following case scenario:
I have a integration test like this:
# cookbook_webtest/test/integration/default/serverspec/localhost/webtest_spec.rb
rules_version = '2'; | |
service cloud.firestore { | |
match /databases/{database}/documents { | |
function isAdmin() { | |
let adminData = get(/databases/$(database)/documents/permissions/admin).data; | |
return isCompany() && request.auth.uid in adminData.userIds | |
} | |
# The command to see the space used under each directory is `du -sh /*` | |
# The `2> /dev/null` at the end is to avoid get lost with a lot of minor errors. | |
# For the example 'mydockerimage' is the name of the Docker image to be checked. | |
# Another way is to use Dive (https://github.com/wagoodman/dive), a really nice tool for this. | |
docker run --rm -u root --entrypoint "" mydockerimage du -sh /* 2> /dev/null |
# To have the last stable version of Chef (10.14.4) | |
# with the official Vagrant boxes | |
config.vm.provision :shell, | |
:inline => "gem search -i chef -v 10.14.4 || gem install chef -v 10.14.4 --no-rdoc --no-ri" | |
# with the official Opscode boxes | |
config.vm.provision :shell, | |
:inline => "/opt/chef/embedded/bin/gem search -i chef -v 10.14.4 || /opt/chef/embedded/bin/gem install chef -v 10.14.4 --no-rdoc --no-ri" |
cookbook 'apt' | |
cookbook 'monit' | |
cookbook 'logstash', git: 'git://github.com/lusis/chef-logstash.git' |
#!/usr/bin/python | |
# -*- coding: utf8 -*- | |
# | |
# Copyright (c) 2008-2012, Juanje Ojeda Croissier <jojeda@emergya.com> | |
# | |
# This program is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU Lesser General Public | |
# License as published by the Free Software Foundation; either | |
# version 2.1 of the License, or (at your option) any later version. | |
# |
load 'rake/helper.rb' | |
desc "Set up the VM" | |
task :up do | |
vm = VM.new | |
vm.cli('up') | |
end | |
desc "Shutdown the VM" | |
task :graceful_down do |
# cookbook/files/default/pushover_handler.rb | |
require "net/https" | |
module MyOrg | |
class PushOver < Chef::Handler | |
def initialize(config={}) | |
@config = config | |
end |
Vagrant::Config.run do |config| | |
# Every Vagrant virtual environment requires a box to build off of. | |
config.vm.box = "base" | |
# Assing IP to the VM | |
config.vm.network :hostonly, "10.0.33.10" | |
# Share directory between the host and the VM | |
config.vm.share_folder "git","/opt/git","/home/anarey/git/djandoapps" |
This is a short and simple example of custom assertions for Minitest.
They are very basic, but they help me to learn it. And I can use the to test some very simple use case of remote conection without install a bunch of gems.
I learn what I needed for this from this article and the minitest-chef-handler's code.
It can be improved a lot using Nokogiri and other Ruby libraries.