Class: MrMurano::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/MrMurano/Mock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMock

Returns a new instance of Mock.



16
17
# File 'lib/MrMurano/Mock.rb', line 16

def initialize
end

Instance Attribute Details

#testpoint_fileObject

Returns the value of attribute testpoint_file.



14
15
16
# File 'lib/MrMurano/Mock.rb', line 14

def testpoint_file
  @testpoint_file
end

#uuidObject

Returns the value of attribute uuid.



14
15
16
# File 'lib/MrMurano/Mock.rb', line 14

def uuid
  @uuid
end

Instance Method Details

#create_testpointObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/MrMurano/Mock.rb', line 51

def create_testpoint
  uuid = SecureRandom.uuid
  template = ERB.new(mock_template)
  endpoint = template.result(binding)

  Pathname.new(testpoint_path).open('wb') do |io|
    io << endpoint
  end
  uuid
end

#mock_templateObject



36
37
38
39
# File 'lib/MrMurano/Mock.rb', line 36

def mock_template
  path = mock_template_path
  ::File.read(path)
end

#mock_template_pathObject



47
48
49
# File 'lib/MrMurano/Mock.rb', line 47

def mock_template_path
  ::File.join(::File.dirname(__FILE__), 'template', 'mock.erb')
end

#remove_testpointObject



62
63
64
65
66
67
68
69
# File 'lib/MrMurano/Mock.rb', line 62

def remove_testpoint
  file = Pathname.new(testpoint_path)
  if file.exist?
    file.unlink
    return true
  end
  false
end

#showObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/MrMurano/Mock.rb', line 19

def show
  file = Pathname.new(testpoint_path)
  if file.exist?
    authorization = %(if request.headers["authorization"] == ")
    file.open('rb') do |io|
      io.each_line do |line|
        auth_line = line.include?(authorization)
        if auth_line
          capture = /\=\= "(.*)"/.match(line)
          return capture.captures[0]
        end
      end
    end
  end
  false
end

#testpoint_pathObject



41
42
43
44
45
# File 'lib/MrMurano/Mock.rb', line 41

def testpoint_path
  file_name = 'testpoint.post.lua'
  path = %(#{$cfg['location.endpoints']}/#{file_name})
  path
end