Module: PDQTest::Instance
- Defined in:
- lib/pdqtest/instance.rb
Constant Summary collapse
- TEST_DIR =
'/cut'
- @@keep_container =
false
- @@active_container =
nil
Class Method Summary collapse
- .get_active_container ⇒ Object
- .get_keep_container ⇒ Object
- .run(example = nil) ⇒ Object
- .set_keep_container(keep_container) ⇒ Object
- .shell ⇒ Object
Class Method Details
.get_active_container ⇒ Object
12 13 14 |
# File 'lib/pdqtest/instance.rb', line 12 def self.get_active_container @@active_container end |
.get_keep_container ⇒ Object
16 17 18 |
# File 'lib/pdqtest/instance.rb', line 16 def self.get_keep_container @@keep_container end |
.run(example = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pdqtest/instance.rb', line 24 def self.run(example=nil) # needed to prevent timeouts from container.exec() Excon.defaults[:write_timeout] = 1000 Excon.defaults[:read_timeout] = 1000 @@active_container = PDQTest::Docker::new_container(TEST_DIR) Escort::Logger.output.puts "alive, running tests" status = PDQTest::Puppet.run(@@active_container, example) if @@keep_container Escort::Logger.output.puts "finished build, container #{@@active_container.id} left on system" Escort::Logger.output.puts " docker exec -ti #{@@active_container.id} bash " else PDQTest::Docker.cleanup_container(@@active_container) @@active_container = nil end status end |
.set_keep_container(keep_container) ⇒ Object
20 21 22 |
# File 'lib/pdqtest/instance.rb', line 20 def self.set_keep_container(keep_container) @@keep_container = keep_container end |
.shell ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pdqtest/instance.rb', line 44 def self.shell @@active_container = PDQTest::Docker::new_container(TEST_DIR) # In theory I should be able to get something like the code below to # redirect all input streams and give a makeshift interactive shell, howeve # I'm damned if I get get this to do anything at all, so instead go the # easy way and start the container running, then use system() to redirect # all streams using the regular docker command. Works a treat! # @@active_container.tap(&:start).attach(:tty => true) # @@active_container.exec('bash', tty: true).tap(&:start).attach( :tty => true, :stdin => $stdin) { |out, err| # puts out # puts err # } system("docker exec -ti #{@@active_container.id} bash") if @@keep_container Escort::Logger.output.puts "finished build, container #{@@active_container.id} left on system" Escort::Logger.output.puts " docker exec -ti #{@@active_container.id} bash " else PDQTest::Docker.cleanup_container(@@active_container) @@active_container = nil end end |