Class: Gitlab::QA::Component::MailHog

Inherits:
Object
  • Object
show all
Includes:
Scenario::Actable
Defined in:
lib/gitlab/qa/component/mail_hog.rb

Constant Summary collapse

MAILHOG_IMAGE =
'mailhog/mailhog'.freeze
MAILHOG_IMAGE_TAG =
'v1.0.0'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Scenario::Actable

#act, included

Constructor Details

#initializeMailHog

Returns a new instance of MailHog.



17
18
19
20
# File 'lib/gitlab/qa/component/mail_hog.rb', line 17

def initialize
  @docker = Docker::Engine.new
  @environment = {}
end

Instance Attribute Details

#dockerObject (readonly)

Returns the value of attribute docker.



13
14
15
# File 'lib/gitlab/qa/component/mail_hog.rb', line 13

def docker
  @docker
end

#environmentObject

Returns the value of attribute environment.



14
15
16
# File 'lib/gitlab/qa/component/mail_hog.rb', line 14

def environment
  @environment
end

#nameObject



22
23
24
# File 'lib/gitlab/qa/component/mail_hog.rb', line 22

def name
  @name ||= "mailhog"
end

#networkObject

Returns the value of attribute network.



14
15
16
# File 'lib/gitlab/qa/component/mail_hog.rb', line 14

def network
  @network
end

Instance Method Details

#hostnameObject



26
27
28
# File 'lib/gitlab/qa/component/mail_hog.rb', line 26

def hostname
  "#{name}.#{network}"
end

#instanceObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/gitlab/qa/component/mail_hog.rb', line 30

def instance
  raise 'Please provide a block!' unless block_given?

  prepare
  start

  yield self
ensure
  teardown
end

#prepareObject



41
42
43
44
45
46
47
# File 'lib/gitlab/qa/component/mail_hog.rb', line 41

def prepare
  @docker.pull(MAILHOG_IMAGE, MAILHOG_IMAGE_TAG)

  return if @docker.network_exists?(network)

  @docker.network_create(network)
end

#restartObject



60
61
62
# File 'lib/gitlab/qa/component/mail_hog.rb', line 60

def restart
  @docker.restart(name)
end

#set_mailhog_hostnameObject



71
72
73
# File 'lib/gitlab/qa/component/mail_hog.rb', line 71

def set_mailhog_hostname
  ::Gitlab::QA::Runtime::Env.mailhog_hostname = hostname
end

#startObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/gitlab/qa/component/mail_hog.rb', line 49

def start
  docker.run(MAILHOG_IMAGE, MAILHOG_IMAGE_TAG) do |command|
    command << '-d '
    command << "--name #{name}"
    command << "--net #{network}"
    command << "--hostname #{hostname}"
    command << "--publish 1025:1025"
    command << "--publish 8025:8025"
  end
end

#teardownObject



64
65
66
67
68
69
# File 'lib/gitlab/qa/component/mail_hog.rb', line 64

def teardown
  raise 'Invalid instance name!' unless name

  @docker.stop(name)
  @docker.remove(name)
end