Background - systems, development, agile, puppet. Builds on James’ talk, a good place to get started.
.Horror stories
we pushed a fact that worked when you ran it with facter, but not with puppet I think the confine was at the wrong level or something weird like that? had to clusterssh into many many many machines and remove it..
If I have to ssh into a box I’ve failed
Simon Willison telling me one of Jesse Robbins (Amazon, now opscode) used to go around data centre and unplug things. Luke Kaines throw it out window
Bug #1
Infrastructure is code
Productive in 4 hours.
babel
Language you might hear on list * TDD, BDD, WTF * problem - works on my machine! * problem - vague naming (domainname)
Capture intent
Systems view of testing - Testing from a sys admins view '[' Destructive testing (load tests, penetration testing) - Hammer Test system, test environment.
Dan north, way to describe testing, Whether at the code level, the application level or beyond, we can use the same thinking and the same linguistic constructs to describe behaviour at any level of granularity.
Why test * quality pyramid, internal external * spaghetti code * broken code - ec2 * red green refactor * inherent complexity in facter == difference between systems. * FEEDBACK and cost of change!
Simplest thing to get the test to pass
Our test is not actually testing what we want. How can we test so it works on my machine and your machine?
language, expectations,
mock objects
1 Favorite
Jonathan Boutelle, entrepreneur CTO at SlideShare, favorited this 1 month ago
module Facter
module Util
class HostnameResolver
end
end
end
describe Facter::Util::HostnameResolver do
it "should return 'foo.example.com' when hostname returns foo.example.com"
end
Facter::Util::HostnameResolver
- should return 'foo.example.com' when querying hostname
returns foo.example.com (PENDING: Not Yet Implemented)
Pending:
Facter::Util::HostnameResolver should return
'foo.example.com' when querying hostname returns
foo.example.com (Not Yet Implemented)
./unit/hostname_spec.rb:4
Finished in 0.0019 seconds
1 example, 0 failures, 1 pending
describe Facter::Util::HostnameResolver do
it "should return 'foo.example.com' when querying hostname returns foo.example.com" do
Facter::Util::HostnameResolver.new.hostname.should == "foo.example.com"
end
end
spec --options spec.opts unit/hostname_spec.rb
Facter::Util::HostnameResolver
- should return 'foo.example.com' when querying hostname
returns foo.example.com (FAILED - 1)
1)
NoMethodError in 'Facter::Util::HostnameResolver should
return 'foo.example.com' when querying hostname returns
foo.example.com'
undefined method `hostname' for
#<Facter::Util::HostnameResolver:0x12e71f0>
./unit/hostname_spec.rb:12:
Finished in 0.002085 seconds
1 example, 1 failure
module Facter
module Util
class HostnameResolver
def hostname
end
end
end
end
describe Facter::Util::HostnameResolver do
it "should return 'foo.example.com' when querying hostname returns foo.example.com" do
Facter::Util::HostnameResolver.new.hostname.should == "foo.example.com"
end
end
'Facter::Util::HostnameResolver should return 'foo.example.com' when
querying hostname returns foo.example.com' FAILED
expected: "foo.example.com",
got: nil (using ==)
./unit/hostname_spec.rb:14:
module Facter
module Util
class HostnameResolver
def hostname
"foo.example.com"
end
end
end
end
Facter::Util::HostnameResolver
- should return 'foo.example.com' when querying hostname
returns foo.example.com
Finished in 0.001872 seconds
1 example, 0 failures
mock objects
describe Facter::Util::HostnameResolver do
it "should return 'foo.example.com' when querying hostname returns foo.example.com" do
Facter::Util::Resolution.expects(:exec).with("hostname").returns("foo.example.com")
Facter::Util::HostnameResolver.new.hostname.should == "foo.example.com"
end
end
Mocha::ExpectationError in 'Facter::Util::HostnameResolver should return
'foo.example.com' when querying hostname returns foo.example.com'
not all expectations were satisfied
unsatisfied expectations:
- expected exactly once, not yet invoked:
Facter::Util::Resolution.exec('hostname')
require 'facter/util/resolution'
module Facter
module Util
class HostnameResolver
def hostname
Facter::Util::Resolution.exec("hostname")
end
end
end
end
Questions?
Further Info
• rspec book - http://www.pragprog.com/
titles/achbd/the-rspec-book
• TDD http://www.mockobjects.com/book/
tdd-introduction.html
• IRC - #puppet #puppet-dev
• github - other peoples code
0 comments
Post a comment